Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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"

share|improve this question
1  
DOS doesn't have Task Scheduler. Only Windows does. –  grawity Oct 27 '10 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 '10 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. –  Gilles Oct 27 '10 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. –  Dennis Williamson Oct 28 '10 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. –  Scott McClenning Oct 28 '10 at 3:59

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
Running in January will just have to be careful –  random Oct 28 '10 at 0:20
    
@random: Why? The if should accommodate that. –  Dennis Williamson Oct 28 '10 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 '10 at 12:54
C:\>move /Y \\your Network server\PROD\PM\FileArchive\2011*.txt \\your Network server\PROD\PM\FileArchive\Documents
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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