Check for date in flat files and then copy them to a backup directory.
Posted on 2003-10-28
First, i will explain my scenario and then the problem i am facing:
Our office has 21 centers and i get 2 types of .DAT files from each and every
center daily. These files are generated with a lag of 7 days as compared to the
system date, i.e., if today it's 2003/10/28 the date in the file will be
Now, when the files come to the Head-Office(where i work), i need to check for
the date of 2003/10/21 and then if the date is correct in all the files i need
to take a backup of all these files into a separate directory. The advantage
here i have is, each file comes with the center#, like 1_INV.DAT, 1_REC.DAT,
2_INV.DAT, 2_REC.DAT, etc
But the real problem that i am facing is of CHECKING THE DATE in the files -- that too i have an idea, but unable to implement?
To check the date, i am first manually running the command:
find /C "2003/10/21" 1_INV.DAT
-->which gives me the count of rows in the file
And then to take a copy of all the files with a script as below:
for /f %%a in ('dir \\pfs\centers\*INV.DAT \\pfs\centers\*REC.DAT /S /b') do (
if not exist \\pfs\centers\%%a copy %%a \\pfs\ctr-bkp\DATBkp%CURDATE%
Now, what i am looking at is, how can i check for the lag of 7 days and after
checking for the difference of the 7 days i want to take a backup of all the
files into the directory with the system date and if there isn't a match of the
date in any of the files then create a file with ZERO bytes and copy the same
into the backup directory.
Thanks in Advance,