My goal is to have a .bat that I can use to automatically archive folders via copy, rename the original folder and the files within with the current date and then clean out old production files.
- Copy target folders to the "Completed" directory
- Update date on the source folders using the format
Previous Name_Today's Date
(MMDDYY) - Update the date of the INDD files within the source folder using the format
Current Name_Today's Date
(MMDDYY) - "Clean" the source folder by deleting all .VPS and .PDFs files within the source folder
I am a novice but I have pieced together this code from research and sources:
@echo off
setlocal enabledelayedexpansion
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
set today=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%
xcopy /s /e /q /y "G:\...\Annual_*" "G:\...\_DONE\"
xcopy /s /e /q /y "G:\...\Life_*" "G:\...\_DONE\"
MOVE "G:\...\Annual_*" "G:\...\Annual_today"
MOVE "G:\...\Life_today" "G:\...\Life_today"
FOR /M *.indd /C "cmd /c rename @file \"@fname - today.indd\""
del /s "G:\...\Annual_today" *.pdf
del /s "G:\...\Annual_today" *.vps
del /s "G:\...\Life_today" *.pdf
del /s "G:\...\Life_today" *.vps
"G:\...\New_Job.bat" > output.txt
My end goal is to be able to change the directory path for the source and archive folders so I can reuse this script for different clients files.
Current Issues
As it stands the script doesn't copy and create an archive folder files and just, deletes all VPS and PDF files from all directories, not just the target folder.
I'm not sure if I'm performing the date check correctly to then use it as a variable to rename future folders and files.
I don't know if FOR /M *.indd /C "cmd /c rename @file \"@fname - today.indd\""
is correct to rename the files. The names are a PO number (6digits) then a title, underscore and then the date.
123456_Life_Kit_020819 for example.
Help would be greatly appreciated!
Here's an Example of what the script should do
Copies the WHOLE folder to the _OLD/Archive folder for each one. Then renames the folder and the contents extensions to the "current date". Then deletes the .pdf and .vps files in the NEW date directories only.
Here is an example of the folder structure.
Main directory:
Inside one of the subdirectories:
The only things I'm trying to rename are the MAIN directory folders with the dates (after copying) and then the files within the subdirectory.
No other folders need to be renamed.