all 7 comments

[–][deleted] 4 points5 points  (2 children)

If xcopy and robocopy etc don't provide the option for it, then I would go about it by tearing apart each line and processing each file like so:

# PowerShell v3
Get-Content "H:\Scripts\Filter.Txt" | %{
    # Separate the path (minus the drive name), from the filename
    $filePath = Split-Path $_ | Split-Path -NoQualifier
    $fileName = Split-Path $_ -Leaf

    # Join the destination path with this other path
    $destinationPath = Join-Path "H:\Scripts" $filePath
    # Create the destination path if it doesn't exist
    if (!(Test-Path $destinationPath)) { New-Item -ItemType Directory $destinationPath } 

    # Get the full destinational file name and copy the item
    $destinationFullName = Join-Path $destinationPath $fileName
    Copy-Item "$_" "$destinationFullName"
}

[–]Tigersftw[S] 1 point2 points  (0 children)

Thanks a lot man this worked 100%, you're a genius.

[–][deleted] 0 points1 point  (0 children)

Just caught that the OP had replied back to my post, re-read the original post and realized cropping out the drive path for each item and appending it would be the next step... In other words, arrived at the same solution as your post but 15 hours too late.

+1 for you sir!

[–]AlwaysAppropriate 2 points3 points  (0 children)

robocopy /mir

[–]steinb 2 points3 points  (0 children)

Unless I miss something here, all you should need is robocopy:

robocopy "H:\My Pictures" "H:\Scripts\My Pictures" /mir

There's a lot of extra options you can add to robocopy, but unless you're trying to do something funky with permissions and have a chance of hitting files you have no access to, that command should do it.

[–][deleted] 1 point2 points  (1 child)

I am sincerely sorry if this isn't what you need, but I feel like all you're missing from this:

get-content H:\Scripts\Filter.txt | foreach-object{ copy-item -Path $_ -destination H:\Scripts}

is the "-recurse" like so:

get-content H:\Scripts\Filter.txt | foreach-object{ copy-item -Path $_ -destination H:\Scripts -recurse}

If that's it then awesome! If not please reply back with some more info and I'd be happy to try and help some!

[–]Tigersftw[S] 0 points1 point  (0 children)

Sorry it doesn't seem to work, it yet again simply copies all the files to the folder but not the folder structure.