MoveFolderX: Failed to move folder. Exception: (path) is denied

I use UiPath Studio activity ‘MoveFolderX’ to move folders within OneDrive.
It used to work very well for about 2 years, up until recently, as it began to issue such an error:

Failed to move folder. Exception:\r\nMove folder exception\r\nAccess to the path ‘(my path)’ is denied.

The worse thing is that now it moves only part of the folder, and leaves partial copies (complimentary) in the source and the destination…

What is going on ?!

@Udiar,

Check if the bot have read/write access to the folder path.

Hi @Udiar

Could you please check if full control (read/write permissions) is still there on the folder and the files you are trying to move.

1 quick way would be to manually move the folder and see if you are able to do so?

also check if path has changed recently? for us, we recently observed on our new win 11 machines setup, default onedrive folder name was different from our other older win 10 machines. But that may not be your scenario, just sharing that as an example to help you narrow down the issue.

Hi @Udiar

Firstly check the file path access and if you have access then use the full path for both.

Happy Automation

If the bot doesn’t have read/write access to the folder path, how could it moved part of the folder?

If the bot doesn’t have permissions, how could it moved part of the folder?

Hi @Udiar

That’s why I said to check for files as well, may be some of the files can’t be moved from that folder. Also, by any chance, any of the files in the folder are being used by any other application?

Are you able to move the full folder manually? if yes, then may be some glitch in automation.

@Udiar,

Some files also could be read/write protected. Try putting a sample file to test if your code is able to move it or not. This will help you to finalize where is the issue. is it at code or at file access control.

@Udiar

  1. Check permissions at file level and not folder
  2. check if the files which are failing if they have special characters in in like . / etc
  3. Use move file and give the filepath which is failing and check if it fails again
  4. are the files in use while moving?
  5. is it from any shared path? if so it might be being used by someone else at the same time

cheers

Yes, I can manually move the folder with no issues.

Hi @Udiar

Could you please confirm below?

  1. did you try the same folder manually that’s failing using UiPath? Or a different one?

  2. the files that didn’t move from the folder, can you try moving those files manually?

  3. by any chance, any of the files that didn’t move were in use/locked when move was being attempted?

  4. any of these pending files have file paths exceeding 260 characters?

  5. any of these files were hidden or are these system files?

If you are unsure of answers to these questions,

You can try below solution instead of using move folderx activity. This would help you gain good view in which file did the move failed. Also you can skip that file and attempt moving rest of the files.

  1. use
    Directory.GetFiles(source folder here, “*”, SearchOption.AllDirectories)
    and manually move files via a loop.

  2. inside loop, surround the move file part by try catch. Catch the error thrown while moving a file , log it and move to next file.

This way you will know in the end which files were problematic and the reason of failure for individual files. Then you can handle those file errors.

Hope this helps.

Regards
Sonali