0

I have a file (e.g. list.txt) with list of paths of files e.g.

F:\users\user\desktop\f1.doc
F:\users\user\desktop\f2.doc
F:\users\user\documents\f3.doc
F:\users\user\documents\f4.doc

I also have attached to my computer an F: drive that has these and other files in it that do not appear in list.txt

I would like to copy all the files on the F: drive that do not belong to the list.txt list but keep the folder structure intact.

something like "copy-item F:\users\user\desktop\f2a.doc -destination C:\copied\users\user\desktop\f2a.doc" but for all files in on the F: drive.

I am guessing I will have to use -filter since the -exclude doesn't work as intended but I don't know how. Any help is much appreciated.

Kamal

Here is the code I have so far:

$file = "list.txt"
$target = "c:\copied\"

$prevDir = "c:\dummy"
$count = 0

foreach ($line in Get-Content $file){
 $currDir = (Get-ChildItem $line).Directory
 if ($currDir -ne $prevDir) {
    $files = Get-ChildItem $currDir -Recurse
    foreach ($item in $files) {
        if ($item -ne (Get-ChildItem $fullPath).Name) {
            Copy-Item $item.FullName -Destination $target + $line
            $count++
        }
    }       
}

$prevDir = $currDir

}
</pre>
Kamal
  • 383
  • 1
  • 6
  • 16
  • There's no need to script this. Just use robocopy. It allows subtree copying, exclusion file specs, automatic retries, logging, and more. – Bill_Stewart Mar 09 '15 at 18:33
  • Depending on how many files are in the exclusion file that may not be very practical. I don't think robocopy will allow a text file of exclusions, I think it wants a list of excluded files, and if his exclusion list has hundreds of files then the command line starts to become ridiculous and there may be length issues with truncation. – TheMadTechnician Mar 09 '15 at 18:40
  • Depending on the use case, one could build a list of exclusions and pass it to robocopy's command line. But hundreds of exclusions makes one wonder if perhaps an include list would be a better choice than an exclude list. – Bill_Stewart Mar 10 '15 at 14:51

1 Answers1

0

I ended up writing a little program in C# to accomplish this. Anyone interested in the code can find it here: https://github.com/ecofriend/CryptoFileSaver

Kamal
  • 383
  • 1
  • 6
  • 16