Batch: Copy files from txt file into one folder

后端 未结 3 386
我在风中等你
我在风中等你 2021-01-07 01:51

I am attempting to create a batch file to copy several files listed in a text file to a new folder. I have found several threads relating to this, but I can still not get th

3条回答
  •  醉梦人生
    2021-01-07 02:24

    I have found that the easiest way to do this is to use a powershell script.

    $Files = Get-Content File-list.txt
    $Dest = "C:\output"
    
    foreach ($File in $Files) {
      Copy-Item $File $Dest
    }
    

    If you need to run it from a batch file, paste the above script to file named CopyFiles.ps1 and add the following command to your batch file

    powershell -executionpolicy bypass -file .\CopyFiles.ps1
    

    Since, powershell is included by default on Windows7 and newer, this method is as easy as doing the same with batch commands only.

提交回复
热议问题