Check for date in flat files and then copy them to a backup directory.

Posted on 2003-10-28
Last Modified: 2010-04-14
Hello All,

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:
@echo off

set CURDATE=%DATE:~10,4%%DATE:~7,2%%DATE:~4,2%
md \\pfs\ctr-bkp\DATBkp%CURDATE%

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,
Question by:sudhakarpv
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 9654851
I guess you want something like:

Check [x]_INV.DAT for [date]
if [date] found, copy to [backup-dir]
if [date] not found, copy an empty file to [backup-dir]

If that is what you need, then here is a skeleton for the task:

@echo off
REM Let's call this job TEST.CMD

REM First we check if we are called with any parameters:
REM IF True: we go do the action
REM If false: we do the outer loop (calling ourselves for each center

      IF .%1.==.. GOTO JOB

REM We will call this job again for each center, and exit when done:
      set DATESTRING=(you must define the datestring here)
      md \\pfs\ctr-bkp\DATBkp%CURDATE%
      FOR /L %n in (1,1,21) DO TEST %n


REM The action per center-file begins here...

find %DATESTRING% %1_INV.DAT          ' have find look for the desired date in the file....
IF NOT ERRORLEVEL 1 GOTO INV_OK       ' if FIND doesn't find anything, it will return errorlevel 1

(put your action for 'date not found' here, - e.g. to create the empty file)



(put your action for 'date found' here, - e.g. to copy/move the file to the bkup-dir)



Author Comment

ID: 9677115
Hello Sven,

Thank you for the reply and the thought.
But, after i posted the question, i got another doubt, which is regarding the date and it's comparison with the date in the file:
I am able to get the date through the date command and catch it in a variable, but the date in the file is of the format 2003/10/28
So, now if i want to check this date through the variable, how can i do it, because the DATE which i am using to catch in the variable gives me the SYSTEM date and then from that i need to subtract 7days, then store it in a variable and then do a comparison of this variable with that in the file.

I hope you got my point; even in the beginning i specified the same that the DATE in the file will be of 7days lag when compared to today's date(system date), that is, if today's date is 2003/11/04 then the date in the file will be 2003/10/28
--------this is the one i am looking for and unable to get to the part of this.

Please advise me and correct me, if i am wrong. And in the mean time i will try the tip you suggested.

WIth Regards,

Accepted Solution

svenkarlsen earned 250 total points
ID: 9678186
ok, I understand.

I do not know of any CMD in W2K which will perform command-line arithmetic on dates. You will either have to input the date manually or consider using scripting for the task instead.

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question