I have a ton of user directories, that I need to move along with permissions to another location, the command I use on an individual basis is :

robocopy "\filer\home" "h:\UserHome" /E /SEC /Copy:DATSOU /log:c:\logfile.txt

Is there a way that robocopy can point to a list of directories in a test file, that need to be moved, instead of doing it one by one which is the way im currently doing.

  • What version of Windows
    – Ryan Ries
    Dec 12, 2014 at 13:33

2 Answers 2


Create a file named directories.txt:


Then write a Powershell script named RobocopyDirsFromList.ps1:

Foreach ($Directory In Get-Content .\directories.txt)
    robocopy "$Directory" "h:\UserHome" /E /SEC /Copy:DATSOU /log:c:\logfile.txt 

Note: I've not tested this, please test first.

  • Couldn't get this to work, tried a few different scenarios, the directories I put in as \\servername\folder\username but the script flashed up a command screen then disappeared. Didn't create a logfile either, im local admin on the server, and have all the permissions.
    – JJJJNR
    Dec 19, 2014 at 9:55
  • The above code is more of skeleton example. Immediate problem is I assume you need to specify both the source and target folders in the text file. That's tricky - a better solution would be to put the list in a CSV and then use the PowerShell Import-CSV command. Two columns. One for source and one for target. But as this post is 5 years old, probably not going into much more detail. Dec 14, 2019 at 21:34

You need to create folder list file

copy this script and save as BAT/CMD file:

for /f "tokens=*" %%a in (list.txt) do robocopy "%_source%\%%a" "%_dest%\%%a" /E /SEC /Copy:DATSOU /log:c:\logfile.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.