Solved

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

Posted on 2003-10-28
5
144 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
[X]
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
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 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