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>