Copying folders and Subfolders with files using Promises WinJS

Hi,
I have app written in WinJS.
I want to copy a particular folder along with its subfolders and their files. I am so far successful with copying folders. Below is the code for the same.
app.CopyFolder = function (folder, destFolder) {
var replace = Windows.Storage.CreationCollisionOption.replaceExisting;
//console.log("create folder: " + folder.name);
return destFolder.createFolderAsync(folder.name, replace).then(function (newdest) {
return app.CopySubFolders(folder, newdest);
app.CopySubFolders=function(folder, destFolder) {
return folder.getFoldersAsync().then(function (folderlist) {
return WinJS.Promise.join(folderlist.map(function (folder) {
return app.CopyFolder(folder, destFolder);
Now after I have copied all the folders I need to copy their respective files. The problem is I am stuck,I get the files copied but I want to proceed ahead after all the files are written to their respective folders. Below is the code for the same.
app.copyAllFiles = function (fileList, destStorFolder) {
console.log('copyFiles Start...');
var promises = [];
var fileCopied = 0;
var collideOpt = Windows.Storage.CreationCollisionOption.replaceExisting;
return WinJS.Promise.join(fileList.map(function (file) {
return app.copySingleFile(file, destStorFolder);
app.copySingleFile = function (fileObject, destFolder) {
var promises = [];
var fileCopied = 0;
var path = destFolder.path + "\\" + fileObject.folderName;
var collideOpt = Windows.Storage.CreationCollisionOption.replaceExisting;
return Windows.Storage.StorageFolder.getFolderFromPathAsync(path).done(function (folderObjectOfLocalFolder) {
return fileObject.fileObject.copyAsync(folderObjectOfLocalFolder, fileObject.fileName, collideOpt).then(function (fileObject) {
console.log("copied single file:" + fileObject.name);
The problem is when i run the folder copy code and apply breakpoint for the success call back of 
CopySubFolders(source,destination).done(/*my breakpoint*/)
The folders are created.
But when I try to breakpoint for my copyAllFiles,the files are created only when i pass the success call back.
Can anyone tell me what am i doing wrong? How can I proceed ahead only when all the files are written successfully.
Regards,
Ninad 

Hi,
I tried the above solution but what i want is that the action of copying folders and subfolders along with the files should be done with promises and that promise should return only when all folders,sunfolders and their files have been copied. I want to
do it in this way because I want to perform certain second action only when all things are copied.
If I do it the as per the link the function runs in the background and my second action proceed aheads and may cause error if it finds some folder or file missing.
So I came up with following above code,first copy folders then copy. The copy folder works as expected but the files are getting copied only when the file copying code enters the success call back.
Can you please shed light on my code where I am going wrong.
Or is it ok to proceed ahead with the solution you mentioned at the link cause I dont want any runtime crashes.
Regards,
Ninad

Similar Messages

  • Need advice. Is it necessary to put images in folders and subfolders with LR?

    It seems that the concept of spending hours putting files into folders, sub-folders and sub-sub-folders is not needed  with LR. Creating all these folders takes hours, especially if you are like me and need a major reorganization of image organization. My thought is that all images can go into one massive folder as long as they are properly tagged. I can then use LR Smart Collections to essentially virtually organize all my images. I can create many more sorting options using Smart Collections than I can by putting images into a folder. This flies in the face of everything I've learned about storing data on a computer so I'm nervouse to head this direction because it starts with unorganizing my folders and removing all tags so I can start fresh.
    I don't want to take this on only to learn I didn't think of a gotcha issue. One drawback is that you are now committed to find anything by using LR or tags only. What do you think?

    Lee Jay wrote:
    Okay, then be honest.  What would you do if you were me?....So - give me an honest recommendation on a go-forward path (no "coulda, woulda, shoulda's").
    Honestly, I always start off from assessing what you really need or what value you could get from keywording. I wouldn't advise you to add keywords for their own sake.
    Lee Jay wrote:
    Meanwhile, I can already find all my images efficiently in seconds in nearly all cases.  I estimate that there is about one situation per year where having a comprehensively keyworded image store would be helpful in saving me time - perhaps 15 minutes each time that happens.
    Let's pretend that this isn't quite as black and white as you always put it. Let's say we're mainly talking weddings - typically wedding photographers add few keywords, if any. And let's say you do need to find certain images more often - each time you go to meet prospective clients you want to put on your iPad (you?) a portfolio of your best work for their broad type of wedding. So you might have categories like indoors / outdoors / subaqua, particular venues, age groups, religions through humanist,  formal / weird. Let's assume you do judge it worthwhile to increase the number of keywords.
    Lee Jay wrote:
    I could start tagging images now as I collect them.  But then I'd have all those other images that aren't tagged and all the new ones that are.  That means using the smart-collection approach would mean all the new ones were in neat collections, and all the old ones were in a gigantic "untagged" collection with over 100,000 images in it.
    Actually, that is the way I would advise you to go. Don't let the perfect be the enemy of the possible. It's not at all uncommon that people are put off beginning doing some keywording by the scale of the complete task. But beginning with the images that you're currently working on isn't too much extra effort. Even if it turns out that you never eventually do go back and keyword the old stuff, in a year's time you'll have a whole year's worth tagged. While doing so you'll probably adopt ways to make keywording less of a chore. For example you might add metadata presets to slap on overall keywords for the typical shoot "Wedding, Ceremonies, Christian" and then one or more keyword sets if you can justify putting time into varying the keywords between images - eg Bride, Kids, Cake. I wouldn't waste any time building up a hierarchy (do if you want, or not if you don't).
    I simply wouldn't worry about the 100,000 remaining untagged - they'll be easier to tackle once you're you've got the experience / benefits from keywording new stuff. I'd advise you to do it only as and when you need - it's too big a task to do anything else. Let's say you need your best shots of Jewish weddings and - as you're currently keeping a lot of metadata in your head - you know some are in that untagged mass. Find them through the folder system as you do now, whack on some keywords like "Wedding, Jewish, Non-orthodox". All those shots are of the bride - whack on "Bride" (maybe from a keyword set). Hey, she's got an obvious tattoo - let's just add that keyword just in case it'll be useful. And quickly move on. Whatever seems worthwhile.
    Although scripting could help, where's the script? Worthwhile to write/adapt one yourself? Instead for folder names I'd just just smart collections to gather image - eg folder name contains "weddings" - and then slap on the keywords. Sure, there will be some duplication between the pseudo-metadata in the folder names and in keywords, but duplication happens with metadata. In fact, it'll be quicker to search by the keyword "Wedding" than search for images with the keyword "Wedding" and / or with the folder name containing "Wedding".
    So that's how I'd advise you - start with the new work, and deal with the older stuff ad hoc.
    John

  • Copy only files from folders and subfolders

    I need a help.
    I have issue with too long destination part, so I want to use some script or command, to copy all files (just files) from all folders and subfolders to one destination (one specified folder).
    I don't need folders and subfolders, just files.
    I have this issue on Windows 7 Professional.
    Best regards

    Try this batch file. It will overwrite files with duplicated names.
    @echo off
    set Source=d:\My Documents
    set Dest=d:\My New Folder
    xcopy /y "%Source%" "%Dest%\"
    for /F "delims=" %%a in ('dir /ad /b /s "%Source%"') do xcopy /y "%%a\*.*"  "%Dest%"

  • Exporting of pictures with folders and subfolders from Aperture

    I was importing folders with subfolders structure to Aperture 3.
    Is possible later export my pictures from structure in Aperture to folders and subfolders with same structure like it was before importing to Aperture?
    Thanks.
    Roman

    I'm assuming you imported using managed files and not referenced files? If referenced (leaving files in place), then your files are in the same folder structure as before.

  • Note:  Mail.app and Folders with Dovecot - Copying Folders w Subfolders

    I found a problem with Apple Mail regarding folder creation with the new Dovecot Server...
    Say you import some mail from Eudora or some other mail client, and you have folders with no messages, only subfolders (or mailboxes if you want to call them that). The mailbox on "My Mac" appears white instead of blue, and you can see the subfolders just fine and everything looks great. Drag that folder (the white one with subfolders) to your IMAP account to copy it to the server. It will copy just fine. Now try to rename or delete that white folder you just copied to the server. You will get the following error:
    For this example I will call the problem folder "TestFolder"
    The IMAP command RENAME (or DELETE if you try to delete) (to TestFolder) failed with the server error: Mailbox does not exist: TestFolder
    The problem is this:
    Dovecot creates folders and subfolders as separate directories on the server:
    .TestFolder
    .TestFolder.TestSubFolder1
    .TestFolder.TestSubFolder2
    In the above example, there is a folder (or mailbox) called TestFolder with two folders inside it, TestSubFolder1, and TestSubFolder2. This example is the correct way to create a folder with dovecot, or if not "correct", at least you can delete or rename the "TestFolder" without an error.
    What happens with Apple Mail (Mail.app), is that when you drag a white folder to the server, it would create the following:
    .TestFolder.TestSubFolder1
    .TestFolder.TestSubFolder2
    Notice the root folder .TestFolder is missing. This is why you get the error message noted above. If you create .TestFolder in the directory, chmod 700 .TestFolder and chown <username> .TestFolder, you can rename or delete the problem folder (notice it turns blue as well). This gets rather annoying when dealing with multiple folders/subfolders, and is not a real graceful way of dealing with the situation.
    Apparently there is some intended difference with the white folders and blue folders, in that blue folders can contain messages but white folders can only contain other folders. Great, but Mail.app needs to somehow create the folder on the server in a way that is compatible with Dovecot.
    If someone has a developer account (mine keeps complaining that there is missing information, but there is no missing information and won't let me log in), could you post this as a bug report? I'll deal with my developer account later...
    Thanks.

    > It's not that they don't show up in Mail. In Mail, they are in their
    (manually) sorted folders. On the server they are in BOTH their
    sorted folder, AND the main inbox where they first appeared.
    Yes, but what I’m saying is that, according to your reports, even after rebuilding the Inbox of the .Mac account that has the problem, there are still messages in that mailbox on the server that don’t show up in Mail in that same mailbox. Is that correct? This is what doesn’t make sense to me...
    > Mac-mydotmacusername1
    Mac-mydotmacusername2
    [email protected]
    So you have two .Mac accounts and a POP account. You hadn’t mentioned this before, had you? I got the impression that you only had one .Mac account...
    Which account has the problem, i.e. for which account there are messages on the server’s Inbox that don’t show up in Mail even after rebuilding that mailbox? Are you moving messages from a .Mac account’s Inbox to custom mailboxes of that same account or to mailboxes associated with the other .Mac account?
    <hr>
    Try this to determine the scope of the problem:
    1. Go to Apple Menu > System Preferences > Accounts and create a new user account for testing purposes.
    2. Either log out of your main user account or just quit Mail so that it does not interfere with the other user account.
    3. Log in as the newly created user and set up Mail anew there.
    4. For spam-related security reasons, go to Preferences > Viewing and disable Display remote images in HTML messages if it’s enabled.
    5. If you set up a POP account, go to Preferences > Accounts > Advanced and disable Remove copy from server after retrieving a message if it’s enabled, to avoid messages being accidentally removed from the server while testing.
    6. Check whether the problem also happens when logged in as another user.

  • How can I transfer/copy my entire iPhoto library from one iMac to another iMac whilst keeping all the folders and subfolders intact?

    We recently purchased a new iMac for our office (8 GB memory, 2.7 processor, version 10.9.2) and we need to copy the iPhoto library from our other iMac (version 10.9.4) onto the new one. The photos are essential for our work and there are around 53,000 of them all organised into folders and subfolders and then the photos are manually ordered within the albums.
    We have tried connecting the computers but when we tried to access the iPhoto library on the new iMac it says that iPhoto is locked and we do not have permission to view it. We updated iPhoto on the old iMac as we thought that might be the problem but the message still appears. We've been advised to use an external hard drive but we're worried that will corrupt the organisation of the library. We have also been told not to do it over AirDrop / the Server because of the sheer quantity of photos.
    Any advice on how to safely do this would be much appreciated.

    No idea exactly what you did
    if you followed the instructions
    Simply copy the iPhoto Library from the Pictures Folder on the old Machine to the Pictures Folder on the new Machine.
    Then launch iPhoto. That's it.
    This moves photos, events, albums, books, keywords, slideshows and everything else.
    then you have exactly the same thin on your new system that you had on the old
    If you do something differently - like import the library instead of simply opening it - then it will not work
    did you dimply drag the iPhoto library from the pictures folder of the old machine to the pictures folder of the new machine and then launch iPhoto on the new machine?
    and to help it is important to use word correctly since that is the only communications method we have - in iPhoto folders do not contain photos - you view photos in events and you can organize them using albums (which view photos) and folders (which hold either albums or other folders - folders never have photos in them) so your description of the problem is not at all clear since it uses folders incorretly
    LN

  • How to copy a dir structure with files and subdir's in to another dir

    Hi there.
    How can i copy a dir structure with files and subdirs to another dir structure
    ie., all files and dirs in side the dir c:\aDir to c:\copyDir so i should get like c:\copyDir\aDir(all the files and subdirs of adir here)
    Thanks in advance
    Muthu

    File f = new File(dirName);
    if(f1.isDirectory()) {
    String list = f.list();
    then u have perform file io for each file and copy them to dir u want
    [email protected]

  • Closing all folders and subfolders within a window with one command

    In list view, is there a way to close all folders and subfolders within a window with one command, instead of having to close each individually?
    Thanks!

    Thanks, all, for your feedback, but no cigar, yet:
    - opening folders with "option" is possible but problematic
    - none of this solves the question of closing all the folders and subfolders within a window in one shot.
    Any better solution would be appreciated.
    Thanks!

  • How to get the Folders and subfolders collection in Project Manager

    Hi,
    I am trying to get the folders and subfolders collection in Project Manager, so that I will be able to loop through the collection and be able to create a project under the appropriate folder.
    Any suggestions?
    Thanks.
    Bhanu

    Anything you do without submitting to form has to be done on the client side (ususally by JavaScript) using data which has been send already from the server.
    With JavaScript you can do quite a bit. You can download tables which don't necessarilly appear on the screen, loading them into JavaScript arrays by dynamically generating javascript. Then you can pick up events like drop-box selection and use these tables to chose what you do next (e.g. preloading other fields, setting drop box content etc.).
    Or, you can cause forms to be submitted when actions like a selection happen without the user clicking a button. It's generally a matter of how much data you'd need to transmit.
    Another posibility is to use a Java applet, which can generate requests to the server and handle the results as it chooses. That are a number of problems with that but occasionally it's the best solution.
    What you can't do is to handle user input inside a JSP. The JSP has come and gone before the user even gets to see your form.

  • HT204655 Can I create folders and subfolders in the new Photos on my mac?

    I've just started using the new Photos app in the latest Yosemite update on my Macbook Pro.
    Until recently I was using Aperture to sort all my photos into folders and subfolders - I think they were called "events" or "projects" in Aperture. 
    In Aperture, I was creating folders like "1993", "1994", "1995" or "Best of My Family".
    Then I had subfolders within those folders - things like a "Christmas 1995", and perhaps some subfolders within that like "Christmas 1995 at Home", "Christmas 1995 at Parents" as well as things like a "favorite 1995 pics".
    And sometime non-date related folders - things like "Children as Babies" subfolder or "Parents on Vacations" subfolder within the "Family" folder.  
    These folders and subfolders seem to have been carried through to this new Photos app as "iPhotos Events".
    But I dont seem to be able to continue sorting - like creating new subfolders within folders.   For example, in Photos I don't seem to be able to create an album within in an album.
    Am I missing a trick here?
    Is Photos unable to do this?
    Or, is the community please able to suggest another alternative solution - like, would using the Pictures folder in Finder be better, perhaps in conjunction with DropBox instead of iCloud?
    Or another photo organizing app that is able to sort folders and subfolders?
    Thank you for your help in advance!

    One way to create folders, subfolders, albums, is to make sure you have your Sidebar showing (menu - view > sidebar) and then use "Control + mouse click" on a folder you want to create a subfolder or album in to bring up the contextual menu.   You can also do these things in the upper right of the Photos window using the + icon but that always seemed to put those items in the top level of the sidebar so I would have to drag and drop them to the folder where I wanted them to go.
    Lori

  • Import non-Mail mailbox folders and subfolders

    I have, for may years, used another email system in which I have defined a heirarchy of many folders and sub-folders.  Is there any way to import these folders and subfolders into Mail?
    Chuck

    Hello
    they are many way to import files into mail - but
    used another email system
    witch one ? entourage ? outlook ? eudora ? thunderbird ? from pc ? from mac ?
    look to your original mail client app if is possible to export mbox format ??
    Pierre

  • Search into folders and subfolders

    I must realize a procedure ColdFusione that effects the
    search into folders and subfolders
    on the file System that simulates the Windows API, specially
    the function PathMatchSpecW().
    How can I realize it?

    Thanks for the information,
    I must realize an optimistic search of folders and files.
    For example in "C:\App\" I have 3 folders Fp_1, Fp_2, Fp_3.
    Gives the run "C:\App\Fp_*" I must get the list of the 3
    folders.
    I use this code:
    <CFDIRECTORY DIRECTORY="C:\App\Fp_*"
    NAME="MyDir"
    SORT="name ASC">
    <CFTABLE QUERY="MyDir">
    <CFCOL HEADER="NAME:" TEXT="#Name#">
    <CFCOL HEADER="SIZE:" TEXT="#Size#">
    </CFTABLE>
    I have not a record!
    Can you write a correct example code?

  • Looping through folders and subfolders

    Hi,
    I'm about to create a script to check some tifs and jpgs for the right height and width, resolution and so on.
    I could get it to work if I see the files in the content panel (looping through the files by app.document.getSelection ...
    The script needs to check many files in different subfolders (all in one parent folder), so I don't like to use a collection to reveal all files of all subfolders first and then start the script.
    My plan is to choose the parent folder in the folder panel and the script should  loop through each file of each subfolder ...
    So maybe there's someone who knows a solution for this problem, it would be great!
    Thanks a lot,
    Sebastian.

    Wow,
    That was fast, I'll test it tommorow in the morning, thanks a lot so far!
    Hopefully I'll be able to get our scripts together...
    Thanks
    Sebastian
    Am 05.08.2012 um 20:13 schrieb Paul Riggott <[email protected]>:
    Re: looping through folders and subfolders
    created by Paul Riggott in Bridge Scripting - View the full discussion
    This should get you started...
    #target bridge  
    var folders =[];
    folders = FindAllFolders(Folder(app.document.presentationPath), folders);
    folders.unshift(Folder(app.document.presentationPath));
    for(var a in folders){
    var fileList = folders[a].getFiles(/\.(jpg|tif)$/i);
    for(var p in fileList){
    var thumb = new Thumbnail(fileList[p]);
    var height = thumb.core.quickMetadata.height;
    var width = thumb.core.quickMetadata.width;
    var Resolution = thumb.core.quickMetadata.xResolution;
    if(Resolution ==0) Resolution =72;
    //do your processing here
    //$.writeln(decodeURI(thumb.spec) + "," + height + "," + width + "," + Resolution);
    function FindAllFolders( srcFolderStr, destArray) {
    var fileFolderArray = Folder( srcFolderStr ).getFiles();
    for ( var i = 0; i < fileFolderArray.length; i++ ) {
      var fileFoldObj = fileFolderArray[i];
      if ( fileFoldObj instanceof File ) {  
      } else {
             destArray.push( Folder(fileFoldObj) );
      FindAllFolders( fileFoldObj.toString(), destArray );
    return destArray;
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4599891#4599891
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4599891#4599891. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Bridge Scripting by email or at Adobe Forums
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • How do I organize webpages in folders and subfolders in iWeb?

    I'm working on a website with plenty of pages and categories (wines). When I used Dreamweaver earlier I could organize the webpages in folders and subfolders which gave me a great overview. But this seems to be impossible in iWeb.
    How do I organize many webpages in iWeb?
    Is iWeb the right software for this kind of website or is it only for family photoes, hobbies, etc...?
    Or should I use another kind of software? If so - which (easy to use software, please)?
    Any help is very much appreciated.
    Thank you...

    panozfan wrote:
    ...should I use another kind of software? If so - which (easy to use software, please)?
    One free, easy to use, web-based site builder is:
    http://www.ning.com
    ...Its focus is on "social networking" and you can add tabs and sub-tabs to specific pages and external links via the Tab Manager feature. Mouse-over the menu items at this Ning site:
    http://www.openwineconsortium.org
    And here's Ning's product overview:
    http://about.ning.com/product.php

  • Mail folders And subfolders

    I made An mail account with which synchronize with exchange. In outlook i have made within each archive folder I have many subfolders. On my iPad it shows All folders And subfolders totally.
    How can I fold in the folders and subfolders?
    Thanks already

    AFAIK, you can't collapse email folders in the iPhone's Mail app.

Maybe you are looking for

  • Invoice Block due to qty

    Hi All, I have a query on Invoice workflows . I'm trying to design an invoice workflow for Qty Block ( as there is no standard one ... although there is one for Priceblock). The event QuantBlock exists in the business object BUS2081 .but no method li

  • In Acrobat 9, how do I keep the ratio consistent in the distance tool?

    In Acrobat 9, how do I keep the ratio consistent in the distance tool?

  • Picklist duplicate

    hello i just saw an instance where there is a duplicate picklist created. ie, the same sales order has two picklists for the same item with the same quantity. they have two picklists with two different numbers. do you know when and how this can happe

  • Photo booth and garageband

    Ever since i updated to os x mountain lion, photo booth isnt as sharpe as it was iam now delayed  a few seconds on it and now when recording on garageband when laying down a drum beat iam unable now to change the tempo. is there anything that i can d

  • Please slove my problems :(

    Hello, I have two problems with my router 1. Sometimes my router light dose not stable allwayz blinking i press reset button but dosent work for me please tell me solid solution for this 2. i m using 1 ethernet port to use intenet means i have plug m