Home > OS >  Batch search to copy the specified file to the target folder
Batch search to copy the specified file to the target folder

Time:10-06

List. TXT in the following file name
Mp3
glory days.Jiangnan. Mp3
Goodbye. Mp3
Spring moonlit. Mp3
Mp3
sing night fishing boat..

These files are distributed in D: \ music folder, the folder has a classic, pure music and sad songs such as classification of subfolders, mp3 files stored in these sub folders,

Ask ace to help, how to batch will list. TXT music mp3 files in batch is copied to the D: \ target folder?

CodePudding user response:

The sourcePath and targetPath respectively replaced with music and the target folder
 
@ echo off
Setlocal enabledelayedexpansion

Set the sourcePath=E: \ Test \ source
The set targetPath=E: \ Test \ target
The set/a copyCount=0

Dir/s/b! SourcePath!> Filelist. TXT

For/f "delims=" % % I in (list. TXT) do (

I find "% %" filelist. TXT & gt; Findfile. TXT

If! Errorlevel! The equ (0

For/f "skip=2 delims=" % % j in (findfile. TXT) do (
Copy/y % % j! TargetPath! \ % % i> Nul
The set/a copyCount +=1
)

) else (
Echo can 't find the file % % I
)

)

Del filelist. TXT
Del findfile. TXT
Echo * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Echo the copy file success:! CopyCount!
Pause
  • Related