0

I have directory that is continuously being updated with pdf files. The file names look like this:

0001_2014_02_14_000000001_018_001_000.pdf

0001_2014_02_14_000000002_018_002_000.pdf

0001_2014_02_15_000000003_018_001_000.pdf

0001_2014_02_15_000000004_018_002_000.pdf

How would I create a batch file that will parse the date (character place 6) and move the files to a directory called d:\send. To make it more complex I need to subtract 3 days from today's date and only move those files. BTW the modified date of the files won't work. The correct date is the date in the file name.

example: today is 2/21/2014 find the files that have a prefix of 0001_2014_02_18_??????????.pdf and send them to d:\send

Of course today's date will change daily and this will be scheduled to run everyday.

Thanks for your help.

lurker
  • 56,987
  • 9
  • 69
  • 103
  • 1
    This can probably be done using this answer http://stackoverflow.com/questions/51054/batch-file-to-delete-files-older-than-n-days?rq=1 – Preet Sangha Feb 21 '14 at 20:24
  • @preetsangha That link only shows examples for files `older` than a given figure, not exactly equal to it. – foxidrive Feb 22 '14 at 10:11

1 Answers1

0

Test this on some sample files:

@echo off
set day=-3
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
move "????_%yyyy%_%mm%_%dd%_*.pdf" "d:\send"
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • I see where you are going with this. It should work but I am getting "A duplicate file exists or the file cannot be found." Checking the paths and file names now. Stand by. – user3338615 Feb 24 '14 at 17:29