locked
[W8.1]How to copy files from app installed folder to a destination folder? RRS feed

  • Question

  • Is there a way in winrt to copy files created in an app installed folder to a user selected folder, for example say there is a big text file & i want to split it in to several single text files for n characters, after completion of splitting the user is prompted to select a folder & all the splitted files are copied to that folder, is this possible ?
    Saturday, July 11, 2015 11:27 AM

Answers

  • Please see the sample I linked. One of the scenarios is for the FolderPicker. There is also a code snippet in the linked FolderPicker docs. Once you have picked a folder you can copy files into it with StorageFile.CopyFileAsync(StorageFolder). To copy multiple files loop through them and copy each individually.

    Pseudocode:

    StorageFolder target = await FolderPicker.PickFolderAsync
    StorageFolder source = await Package.InstalledLocation.GetFolderAsync("filestocopy");
    files = await source.GetFilesAsync()
    foreach (StorageFile file in files)
    {
        Await File.CopyAsync(target);
    }

    If you need more help then please show what you've done and explain clearly where you are stuck.

    Friday, July 24, 2015 11:09 PM

All replies

  • You can use a filesavepicker to save one file but you cannot save the data to more than one file
    Saturday, July 11, 2015 12:56 PM
  • Are u saying that it's not possible to copy multiple files from a folder to another folder in winrt app ?
    Monday, July 13, 2015 7:45 AM
  • Yes, just as Ken mentioned that it is impossible for you to use FileSavePicker to save more than 1 file. When your Windows Runtime app saves files to the machine, the app must get user's approve, so it is impossible (also unsafe) to save many files with one time user approve. 

    So instead of using FileSavePicker to ask the user to choose the folder, how about you save files in the KnownFolders?

    Wednesday, July 15, 2015 12:08 PM
  • To use KnownFolders i should declare documents library access permission in my manifest file right ?? , can't i make user to select a folder first by clicking a button A  & then later use that folder programatically to save files after clicking button B ??
    Sunday, July 19, 2015 6:16 AM
  • Yes, you're right that you need to specify KnownFolders (MusicLibrary, DocumentLibrary and etc.) in the manifest file.

    For your another issue, you can choose to use the StorageApplicationPermissions.MostRecentlyUsedList to get the folder(s) which is used recently.

    Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(file)
    Also check this article for the details.
    Friday, July 24, 2015 12:42 AM
  • You can use a FolderPicker to pick a folder into which you can copy multiple files.

    See Quickstart: Accessing files with file pickers and the File picker sample

    Friday, July 24, 2015 3:59 AM
  • @Suresh It isn't helpful
    • Edited by kranthi88 Friday, July 24, 2015 1:01 PM
    Friday, July 24, 2015 12:58 PM
  • @Rob I know how to access files with file pickers & using file picker sample, can you provide me a sample for copying multiple files to a user selected folder ?
    • Edited by kranthi88 Friday, July 24, 2015 1:00 PM
    Friday, July 24, 2015 1:00 PM
  • I think this thread has gone off course. Let me reword the question. I want to prompt the user for a destination folder, then I will write n files to that destination.

    http://pauliom.wordpress.com

    Friday, July 24, 2015 3:53 PM
  • Please see the sample I linked. One of the scenarios is for the FolderPicker. There is also a code snippet in the linked FolderPicker docs. Once you have picked a folder you can copy files into it with StorageFile.CopyFileAsync(StorageFolder). To copy multiple files loop through them and copy each individually.

    Pseudocode:

    StorageFolder target = await FolderPicker.PickFolderAsync
    StorageFolder source = await Package.InstalledLocation.GetFolderAsync("filestocopy");
    files = await source.GetFilesAsync()
    foreach (StorageFile file in files)
    {
        Await File.CopyAsync(target);
    }

    If you need more help then please show what you've done and explain clearly where you are stuck.

    Friday, July 24, 2015 11:09 PM
  • well it looks promising, thanx.
    Monday, July 27, 2015 5:42 AM