Extension: To delete the files in a specific folder :
File name is like this xyz_yyyymmdd.dat.gz
Say in a folder E:\ZippedFiles, I have files like these present
xyz_20160526.dat.gz
xyz_20160627.dat.gz
xyz_20160528.dat.gz
xyz_20160529.dat.gz
xyz_20160630.dat.gz
xyz_20160531.dat.gz
xyz_20160601.dat.gz
xyz_20160602.dat.gz
xyz_20160603.dat.gz
File xyz_20160529.dat.gz is a Sunday File and xyz_20160531.dat.gz is the last day of the previous month file.
Expectations:
To move (not copy) the Sunday file and last day of previous month file to E:\Backup
Conditions:
1. Batch file should be configurable to pick a day of week for running the script and is dependent on a user fed variable no_of_days.
Lets say I am running the script on a Friday, so if I pass a variable no_of_days==5, it will backup sunday file.
if on a thursday , then no_of_days becomes 4
basically current_day - no_of_days= Sunday (current day minus no of days should return a sunday) and backup the sunday file.
2. Also, after moving files 20160529 and 20160531. It should not delete any files for the current week but it should delete all the files of the previous week except sunday file if present.
Example: files 20160530,20160602,20160603,20160604 are left in the current folder whereas 20160526,20160527,20160528 are deleted. files 20160529(sunday) and 20160531 are moved to back up folder.
3. after running the batch script expected:
New location: E:\Backup\xyz_20160529.dat.gz and E:\Backup\xyz_20160531.dat.gz
deleted files: E:\ZippedFiles\xyz_20160526.dat.gz, E:\ZippedFiles\xyz_20160627.dat.gz ,E:\ZippedFiles\xyz_20160528.dat.gz
Not modified: E:\ZippedFiles\xyz_20160530.dat.gz, E:\ZippedFiles\xyz_20160601.dat.gz, E:\ZippedFiles\xyz_20160602.dat.gz, E:\ZippedFiles\xyz_20160603.dat.gz,