Should Copy-Item create the destination directory structure?

后端 未结 6 1583
广开言路
广开言路 2020-12-08 12:46

I\'m trying to copy a file to a new location, maintaining directory structure.

$source = \"c:\\some\\path\\to\\a\\file.txt\"
destination = \"c:\\a\\more\\dif         


        
6条回答
  •  广开言路
    2020-12-08 13:43

    None of the current answers worked for me to fix the Could not find a part of the path error raised by Copy-Item. After some research and testing, I discovered this error can be raised if the Destination path goes over the 260 character Windows path length limit.

    What I mean by that is: if you supply a path to the Destination argument of Copy-Item and any of the files you are copying would exceed the 260 character limit when copied to the Destination folder, Copy-Item will raise the Could not find a part of the path error.

    The fix is to shorten your Destination path, or to shorten/flatten the folder structure in the source directory that you are trying to copy.

提交回复
热议问题