Take the 2-minute tour ×

I need a batch file that will find all files in a folder with a set variable in there name and then move them to a different folder. This must work on a windows XP computer.


the folder has these files


if we search for file names that contain "123" then it would move both abc123abc.pdf and efg123eft.pdf to a set folder.

share|improve this question
add comment

2 Answers

If you want the names that have 123 anywhere in them:

move *123*.* c:\newfolder

If you want the 123 to always be the 4th, 5th, and 6th characters:

move ???123*.* c:\newfolder

If you want only .pdf files with 123 (either of the above matches):

move *123*.pdf c:\newfolder

Works either from a batch file or directly from the command prompt.

The ? matches a single character, the * matches one or more. These are called wildcard operators or simply wildcards.

To see how the wildcard operators work, open a command ("DOS") window in the folder you want to use, and try (dir is for a directory listing, and can't hurt anything to experiment with):

dir *.*

dir *123*

dir *123*.pdf

dir ???123*.pdf
share|improve this answer
how do i look through all the files in a folder? –  jardane Aug 8 '12 at 1:27
The examples I gave you do exactly that - the wildcard gives you multiple (one or more) matches. See my last sentence, and see the dir command in the command-line reference. –  Ken White Aug 8 '12 at 1:30
add comment

No need for a batch file - the move command with a wildcard will do that itself:

move *123* c:\where\ever
share|improve this answer
add comment

Your Answer


