Solved

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

Posted on 2003-10-28
5
139 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows 2000 3 425
Norton Ghost for Windows NT 5 1,456
Windows 2000 undelete (free program?) 6 429
Hyper V Virtual Machine not showing on Local Network 3 627
What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now