5

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.

JJJJNR
  • 860
  • 4
  • 20
  • 32

2 Answers2

3

Create a file named directories.txt:

C:\dir1
C:\dir2
C:\dir3
C:\dir4\subdir

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.

Ryan Ries
  • 55,011
  • 9
  • 138
  • 197
  • 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 '14 at 09: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. – Rob Nicholson Dec 14 '19 at 21:34
0

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
Haim Cohen
  • 11
  • 2