I was given a list of 40,000 files to copy from one directory and recreate the to directory in another location. The copy-item does not create the directory so I was going to call robocopy. This probably is the wrong way but having issues.
Current location = OriginalserverFromitem1 in there we need text1.tst but not text2.tst. The next location we may need text2.tst and not text1.tst. The file names are all different and some of the files we want to exclude have the same extension.
We want to copy to AnotherServerOriginalserverFromitem1 but the directory structure below Originalserver does not exist.
Before trying the looping I was just trying to copy the file, exclude the unwanted file, and create the structure. The script below I cannot make robocopy use $thisfile but just the filename works.
$F1 = "copy" $F2 = "From" $T2 = "To" $thisfile = test.txt #Robocopy f:$F1$F2 f:$F1$T2 test.txt Robocopy "f:$F1$F2" "f:$F1$T2" '$thisfile'
2test.txt : The term ‘2test.txt’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:4 char:13 + $thisfile = 2test.txt + ~~~~~~~~~ + CategoryInfo : ObjectNotFound: (2test.txt:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
ROBOCOPY :: Robust File Copy for Windows
Started : Wednesday, July 5, 2017 2:12:04 PM Source : f:copyFromnew Dest : f:copyTo
Files : []
Options : /DCOPY:DA /COPY:DAT /R:1000000 /W:30
0 f:copyFromnew
Total Copied Skipped Mismatch FAILED Extras Dirs : 1 0 1 0 0 0
Files : 0 0 0 0 0 0 Bytes : 0 0 0 0 0 0 Times : 0:00:00 0:00:00 0:00:00 0:00:00 Ended : Wednesday, July 5, 2017 2:12:04 PM
PS C:WINDOWSsystem32>
submitted by /u/overflow3234
[link] [comments]
The post Copy a file and retain the folder structure appeared first on How to Code .NET.