Is there a single PowerShell command to copy and rename files?

前端 未结 2 501
傲寒
傲寒 2021-02-03 21:25

I am using the following command to copy files from a network share to my local hard drive based on a CSV file.

import-csv C:\\TEST\\test.csv | foreach {copy-ite         


        
2条回答
  •  时光说笑
    2021-02-03 22:12

    If your original CSV also had the new name in it, you would be able to use it to specify a filename onto the end of your copy path. The copy-item CMDlet allows you to specify the destination filename

    Copy-Item C:\TEST\file1.jpg C:\TEST\file2.jpg
    

    Will copy file1.jpg and rename it to file2.jpg

    To concatenate the variable onto the end of the path string, you'd use double quotes like this:

    Copy-Item C:\Path\To\File\file.ext "C:\Path\To\New\File\$newfilename"
    

    Note that the -path and -destination aren't really necessary as they're implied by the position.

提交回复
热议问题