Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch Copy file by filename

Tags:

The file I want to copy is located in "C:\Report\" and the filename I want to copy is something like "rptXXXX.txt". What I want to do is write a batch that copy the file that the filename is start with "rpt".

The destination folder is "F:\Project\Report\".

like image 674
gensius Avatar asked Aug 02 '11 04:08

gensius


People also ask

What does %% mean in batch script?

%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt.

How do I write a simple batch file to copy files?

Batch File to Copy FilesUse the command simply called "Copy." Generally, put the word copy on one line, followed by the original file and where you want it copied, such as "copy C:\Example\Example. txt C:\Example2\Example2. txt."

How do I copy a file in CMD?

Highlight the files you want to copy. Press the keyboard shortcut Command + C . Move to the location you want to move the files and press Command + V to copy the files.


1 Answers

This should work, you can use an * as a wildcard:

xcopy e:\foo\rpt*.txt e:\foo2 

or in your case,

xcopy C:\Report\rpt*.txt F:\Project\Report\ 
like image 199
fatty Avatar answered Nov 09 '22 05:11

fatty