Solved Batch move of files that match certain format

February 1, 2013 at 12:30:59
Specs: Windows 7
Need to move all files from one directory that match the format below to another directory

*-*-*.pdf where * must be numeric


See More: Batch move of files that match certain format

Report •

#1
February 1, 2013 at 16:38:40
✔ Best Answer
::====== begin batch
@for /f %%a in ('dir /b \xxx\*-*-*.pdf | findstr /r "[0-9]*-[0-9]*-[0-9]"') do @echo move \xxx\%%a elsewhere
::====== end batch
this will however, pick up files with null between dashes: --999 -8-99 in some cases. Further refinement might be required in the filtering...
Take out the echo when you feel brave and confident..

Report •

#2
February 7, 2013 at 07:33:58
This helps but is moving items I wouldn't expect it to move. I'm testing with 2 files 123-4569-123.pdf and 123-G4569-123.pdf. It moves both of them when I would expect the one with a letter G to not move as it isn't numeric.

Report •

#3
February 7, 2013 at 08:28:08
I think I figured it out

for /f %%a in ('dir /b *-*-*.pdf ^| findstr /r "[0-9]*-[0-9]*-[0-9]"') do move /y %%a elsewhere

I needed a ^ for this to work in my batch code Thank you so much for your help!!!!


Report •

Related Solutions

#4
February 7, 2013 at 08:46:53
my mistake too late in posting edited

Report •

#5
February 7, 2013 at 10:19:53
My mistake most for getting it wrong. I had it right in my "working model", but I must have hand-typed instead of cut/paste to the forum, and in so doing lost the carat (or easter-bunny made early appearance and stole it). "good eye" for catching my goof, glad you got it working.

Report •

Ask Question