Disclamer: Previously I needed to compare the date from "last modified" but 5 minutes ago I got a new requirement that I need to compare with the date on the filename as I explain myself bellow.
Imagine that I have 2 folders:
- C:\FolderData (will be incremented daily with new files)
- C:\FolderTemp (Needs to have only files from the day before executing, excluding hours/timestamp)
The FolderData will receive filenames that if not for date would be equals, as in:
- SYS_PURCHASES_20170617.xls
- SYS_PURCHASES_20170618.xls
- SYS_PURCHASES_20170619.xls
If I run the .bat file today I need that only the SYS_PURCHASES_20170618.xls be copied over to FolderTemp. That have to be accomplished by getting the last 8 characters from the filename (20170618) and checking if it matches to TODAYDATE - 1.
Is this possible with batch-files and if so, how?
Also accepting answers on Windows PowerShell(6.1)
if it also does these steps after:
- Copy all files from folder1 to folder2 when the date in the filenames = currentdate - 1;
- Remove last 9 digits from all files from folder2 (will remove the date and undescore "_YYYYMMDD") so the file will be SYS_PURCHASES.xls (need to consider every file extension, as there will be .xls, .xlsx and .txt);
- Move and replacing the files from folder2 to folder3 (using a simple
move /y
) - I believe it's possible to do this while doing step 2, no need for a third folder.