This was a repost, I had it on stack exchange and was told it was better suited here for the superuser site. Not sure the difference. First time visitor to either site...but here it goes. ~Cheers

I am a novice at best struggling along as my job is evolving and owner will not provide training. Thus, I have a multiple batch files codes that read like this or very similar, ultimately running a nightly report and dropping the pdf file into a shared drive for me.

My batch reads like this and has five reports...I entered two below.

R:\Simply\Simply.exe /u:username /p:password /rpt:"Daily Report" /pgp:Custom /pgs:pdf /el:R:\reports\str001\DailyReports /s

R:\Simply\Simply.exe /u:username /p:password /rpt:"Negative Report" /pgp:Custom /pgs:pdf /el:R:\reports\str001\DailyReports /s

Every morning I have to create a new folder with yesterdays date and move all the files that were generated to this folder.

I should note that this batch needs to run on winxp and win7 so dating from what I have read needs to take this into consideration.

I have read and tried several posts on here. I am not sure where to put the code, how to insert it behind my existing code, infront of, on each line. Again, novice looking for some advice. Hell, I even tried running a new .bat file with only creating a new folder code based on other posts on here...and I couldn't get those to work. I can link them here but that seems a waste of time. Trust me, I've tried to solve this....I enjoy solving and learning but I'm lost. Please help

I'd like to have the batch file create a folder dated with yesterdays date in format of YYYY_MM_DD and then save the files into said folder automatically when it runs rather than me having to move them daily over and over again.

Note: If the date exists I do not want to overwrite the data but would like to drop the files into that location.


This solution assumes your reports are PDFs and that they are the only PDFs in your report folder. Additionally, some of this solution was adapted from:


New batch file contents:


R:\Simply\Simply.exe /u:username /p:password /rpt:"Daily Report" /pgp:Custom /pgs:pdf /el:R:\reports\str001\DailyReports /s

R:\Simply\Simply.exe /u:username /p:password /rpt:"Negative Report" /pgp:Custom /pgs:pdf /el:R:\reports\str001\DailyReports /s

... (more of your report stuff goes here)

SET day=-1
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%"
SET "date-yesterday=%yyyy%_%mm%_%dd%"

IF NOT EXIST %date-yesterday%\ (
    MD %date-yesterday%

MOVE *.PDF %date-yesterday%
  • I ran the batch and all my files (pdf's) were dropped into the shared drive but a new folder with yesterdays date was not created and files were not moved, just loose on the drive still (I should note that I deleted yesterdays reports before I ran....just to make sure there was nothing conflicting from what ran last night) – MissChris Aug 13 '15 at 18:36
  • I modified my IF NOT EXIST line slightly. Bear in mind the batch file must be run from the same path as your shared drive. If it's not, you may want to consider the use of CD in your batch file to change the current working directory or updating the MD and MOVE lines to include a full path. – psouza4 Aug 13 '15 at 18:40
  • YES!! Perfect. TYVM...hours saved a week....and you were dead on. That was it. I had my batch in a batch folder elsewhere. Once I moved it to the same path. It ran perfect. – MissChris Aug 13 '15 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.