1

I am trying to create a task in the Task Scheduler that will automatically move some pdf files into another folder that is based on the date in the pdf files which is for the previous month. The problem I am having is that I can't figure out how to get the command line to roll back to the previous month. I am using the same thing to create the folder to begin with, but the task is set to run at the end of what would be considered the previous month. So for example one task running in October to create the folder for current month 2010-10 and another run in November after the PDFs are compiled that will move them to the 2010-10 folder. Any ideas?

The date parameters I am using are "%DATE:~0,2%" I have tried "%DATE:~0,2% -1" and "%DATE:~0,2%-1" and the full text in the batch file is "move [-Y] *.pdf P:\CBO\Physician Monthly Reports\%DATE:~6,4%-%DATE:~0,2% -1"

7
  • 1
    DOS doesn't have Task Scheduler. Only Windows does. Oct 27, 2010 at 19:47
  • 1
    Yes, but you can create a batch file in Notepad and schedule it to run using Windows Task Scheduler. Besides that the AT command in DOS allows you to schedule tasks.
    – ThaddeusTG
    Oct 27, 2010 at 19:55
  • @ThaddeusTG: grawity is correct. DOS doesn't have the at command, but Windows does. DOS is an operating system that is different from Windows, and that is incapable of scheduling a task for later running. Windows's command line is still Windows, not DOS. Oct 27, 2010 at 20:56
  • 1
    People will continue to call Windows' Command Prompt "DOS" until the end of time. People still call the Memphis-Arkansas Bridge "the new bridge" even though it's almost 40 years old. Oct 28, 2010 at 1:25
  • If the PDF generation and naming are also done by batch, then the batch file that creates that directory can also generate the PDFs with the correct name and store them in the correct folder to start. I have one batch file generate names & folders, the CALL or START the other batch files and the date variable I use in the first batch to create the directories is passed to each CALLed or STARTed batch by default. That way all the batch files know about the same location without recreating the date variable. Oct 28, 2010 at 3:59

2 Answers 2

1

Your character selection requires that your date format looks like "MM-DD-YYYY". This command retrieves the number of the current month and subtracts one and saves it in a variable called prevmonth. It also subtracts one from the year if the previous month is December:

set /a prevmonth=%DATE:~0,2% - 1
set yearprevmo=%DATE:~6,4%
if %prevmonth% equ 0 set /a yearprevmo=%yearprevmo%-1 & set prevmonth=12
move -Y *.pdf "P:\CBO\Physician Monthly Reports\%yearprevmo%-%prevmonth%"

Note the quotes since there are spaces in your directory name.

3
  • Running in January will just have to be careful
    – random
    Oct 28, 2010 at 0:20
  • @random: Why? The if should accommodate that. Oct 28, 2010 at 1:22
  • Thank you for your response, I have seen that a lot on the web, but they were in the different date formats that are available, so I wasn't sure how to put it into the format that I needed. You're right the if should accommodate the issue of running in January.
    – ThaddeusTG
    Oct 28, 2010 at 12:54
1
C:\>move /Y \\your Network server\PROD\PM\FileArchive\2011*.txt \\your Network server\PROD\PM\FileArchive\Documents

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .