locked
[UWP] "Could not find a part of the path" RRS feed

  • Question

  • Hello,

    In the following scenario:

    StorageFolder folder1 = // from folder picker

    StorageFolder fold2 = // from folder picker

    await Task.Run(()

    {

        Directory.Move(folder1.Path, folder2.Path);

        // same error if: Directory.Move(folder1.Path, Path.Combine(folder2.Path + @"\NewDir"));  // NewDir doesn't exist

    });

    I always got exception "Could not find a part of the path C:\\xxx" where xxx is the top folder name in folder2.

    Any idea why?

    Thanks!


    Friday, September 23, 2016 11:57 PM

Answers

  • Use a folder query to get the contents and then call StorageFile.MoveAsync to move them to the new folder.

    You will need to write some code to do this as there isn't a turnkey folder copy API.

    • Marked as answer by Helen.W Monday, September 26, 2016 9:57 PM
    Monday, September 26, 2016 9:10 PM

All replies

  • Use StorageFolder methods instead of Directory.Move. The StorageFolder version goes through the file broker to use the permissions granted by the folder picker. The Directory version uses the app's direct permissions, which it doesn't have for paths outside of its ApplicationData folder. There isn't a direct Move method, but you can build it from the lower level methods.

    See my blog entry Skip the path: stick to the StorageFile

    • Proposed as answer by Azat Tazayan Saturday, September 24, 2016 7:31 AM
    Saturday, September 24, 2016 4:19 AM
  • Thanks for your reply!

    I checked StorageFolder before but didn't know how to achieve the goal. Just checked your blog still don't know what to do.

    What I wanted is to move one folder to another, just as what Directory.Move does.

    Could you please tell me how to make it work using StorageFolder version?

    Many thanks!

    Saturday, September 24, 2016 4:49 PM
  • What part are you having trouble with?

    StorageFolder doesn't have an explicit "Move", so you'll have to break the option down: Create the new folder then move the contents.

    Monday, September 26, 2016 6:27 PM
  • The "Move" part.

    How to move the content?

    Thanks!

    Monday, September 26, 2016 8:56 PM
  • Use a folder query to get the contents and then call StorageFile.MoveAsync to move them to the new folder.

    You will need to write some code to do this as there isn't a turnkey folder copy API.

    • Marked as answer by Helen.W Monday, September 26, 2016 9:57 PM
    Monday, September 26, 2016 9:10 PM
  • Thanks.

    Seems I have to loop through the content.

    Monday, September 26, 2016 9:57 PM