I’m trying to copy files from one location to another. I have a CSV that has the directory, name, and some other fields that aren’t important for the move. I’m pretty sure that my code is trying to move the entire folder structure and not just the file. How can I just move the file? OR How can I move a similar folder structure to the new location (\folder\username)
The directory looks something like:
\\server\folder\username
The code I was trying:
Import-Csv c:\movefiles.csv | ForEach-Object {Copy-Item -LiteralPath ($_.Directory + "\" + $_.name) -Destination c:\}
The destination will actually be a location on another server.
The code your trying should copy the file(as long as the
nameproperty is the name of a file) and save it inc:\just like you wanted. You might want to useJoin-Pathto combine the directory and filename instead of your current approach. It makes sure that you don’t have multiple\etc.. Ex:Copy with folderstructure(untested):
As said, this is untested. Try to use it like this: