Solved

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

Posted on 2003-10-28
5
142 Views
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
2003/10/21
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,
Sudhakar
0
Comment
Question by:sudhakarpv
  • 2
5 Comments
 
LVL 9

Expert Comment

by:svenkarlsen
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



      GOTO EXIT

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

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)

GOTO EXIT

:INV_OK

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


GOTO EXIT



:EXIT
0
 

Author Comment

by:sudhakarpv
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,
Sudhakar
0
 
LVL 9

Accepted Solution

by:
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.
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
auto copy 8 617
Remote Desktop Software 6 458
Windows 7 7 269
Dell PowerEdge raid drive replacement 13 508
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…
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

807 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