0

I got the following problem. I have a folder C:\Users\Username. In that folder you can find folders like "Documents", "Favorites" etc.

What im trying to do is including only some of the folder to copy.

I was playing arround with Robocopy XD to exclude some folder but that is not acceptable cuz i cant know all the folder that may be there.

Then i tried Get-ChildItem -include <some dir>. Now i want to copy only the listed folders. But robocopy copies only the content of the folder and not the folder itself. Are there any other solutions for this problem.

seyo -IV
  • 173
  • 3
  • 13

2 Answers2

4

First : don't forget to use -recurse on Get-ChildItem to grab all the structure in the object.
Then on robocopy:

  • You need /s to include non-empty subdirectories and /e to include the all the subdirs
  • /b and /purge is nice when you are doing backups - greatly increased speed . be careful with purge though
  • /xd <Directory>[ ...] Excludes directories that match the specified names and paths. (or you can include just a list of the desired subdirs)

I use something like this:

$source = 'C:\hold\first test'
$destination = 'C:\hold\second test'
$robocopyOptions = @('/NJH', '/NJS')
$fileList = 'test.txt'
Start robocopy -args "$source $destination $fileList $robocopyOptions"

Also the log option saved my life a couple of times.

For all the parameters see robocopy docs

barbsan
  • 3,418
  • 11
  • 21
  • 28
TudorIftimie
  • 1,050
  • 11
  • 21
  • thank you for the edit ! It is my first try to answer a question - I will improve my style :) – TudorIftimie Apr 11 '19 at 10:00
  • when it comes to `Start robocopy -args "$source $destination $fileList $robocopyOptions"` a cmd shows for like a milisecond and exits again and nothing happened. Maybe this is also a usefull info, i'm using it in a powershell script. – seyo -IV Apr 11 '19 at 10:14
  • you can use `-NoNewWindow -PassThru -Wait` for the window as recommended in the quoted link. But I prefer using logs with a timestamp in the name for each run. – TudorIftimie Apr 11 '19 at 10:35
  • I think i know the problem now. It works only with files not folders – seyo -IV Apr 11 '19 at 10:57
0

I have just found out you can do Copy-Item -Path $path"\Desktop" -Destination $newdir -Recurse and it will copy the Desktop folder with its content.

seyo -IV
  • 173
  • 3
  • 13