Computing.Net > Forums > Programming > Win2k batch: copy only new files?

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

Win2k batch: copy only new files?

Reply to Message Icon

Original Message
Name: Palsam
Date: May 4, 2004 at 05:36:50 Pacific
Subject: Win2k batch: copy only new files?
OS: Win2000 SP4
CPU/Ram: P2/256MB
Comment:

Here's my situation:
Computer A controls a medical device which daily generates a report file.
Computer A runs DOS 6.22 OS and is for safety reasons not connected to the network.

Server B runs Windows 2000 Server OS with a database where the data in the report files from computer A are to be inserted.

The general solution so far is to write a batch file which copies only files generated after previous batch file run, to a floppy disk.
The next step is to transfer and rename the log files from the floppy disk to a temp directory on server B. *I'll propably write this part in VB*.
The last step is to extract the data from the log files and insert them into tha database. *This part has already been created*.

I've tried to create a batch file (xferlogs.bat) based on Richard Bonner's CDUL.bat (http://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv.html#CDUL) which copies all files create forward of given date.
I'd like to automate my batch file so that it retrieves the date on which the script was last run (e.g. from a file), increment it by 1 (i.e finds next day's date) and use this date as an parameter to the CDUL.bat.

My main problem seems to be passing the system variable containing the mentioned date to CDUL.bat. I get an "invalid parameter" error when my script executes the line "CALL CDUL.bat TheDate". If I type "CDUL.bat 09-06-02", the CDUL script executes correctly.
I've included the scripts below.

---
lastdate.txt contains only the date on which the script was last run in the format "mm-dd-yy"
---
Helper file sethelp$ contains only "set result="
---
:: xferlogs.bat (lacks code for finding the date after lastdate)
rem Read date of last action

@echo off
copy sethelp$ + lastdate.txt $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat

call cdul.bat result

rem update lastdate.txt with the current date
---
:: CDUL.bat
:: Copies Files on Today's, or from the Specified Date Forward,
:: to the Upload Directory
::
@ECHO OFF


Rem If no Date is Given, Today's Files will be Copied
IF "%1" == "" GOTO COPY-TODAY

Rem Otherwise, Files will be Copied Forward of the Date Typed
IF NOT "%1" == "" GOTO COPY-DATE

:COPY-TODAY
ECHO. | DATE | FIND /I "Current" > C:\BATCH\CUR-DATE.BAT
ECHO @SET CUR-DATE=%%4 > C:\BATCH\CURRENT.BAT
CALL C:\BATCH\CUR-DATE.BAT

Rem Copies Files based on Today's Date ("NUL" Hides Screen Messages)
XCOPY c:\batch\*.* C:\UPLOAD /D:%CUR-DATE% > NUL

GOTO END

Rem Copies Files based on The Date Given at the Command Line
:COPY-DATE
XCOPY c:\batch\*.* C:\UPLOAD /D:%1 /-Y

Rem Separates the Listing Gives a Listing for the UPLOAD Directory to
Show the Operation's Success
:END
ECHO.
REM CALL C:\BATCH\DR.BAT C:\UPLOAD
DIR c:\upload\*.*

Rem Removes the Date Variable From the Environment
SET CUR-DATE=
---

Does anyone have a suggestion as how to solve this problem, and hopefully update lastdate.txt with the current date? Alternative solutions are also welcomed.

Palsam


Report Offensive Message For Removal


Response Number 1
Name: IVO
Date: May 4, 2004 at 06:37:33 Pacific
Reply: (edit)

I found two mistakes just at the beginning of your script, so I start from there:
1)
copy sethelp$ + lastdate.txt $tmp$.bat > nul
call $tmp$.bat
del $tmp$.bat

This does not set up in $tmp$.bat the wished "Set Result=mm-dd-yy" as joining two files by copying insert a CR/LF between their content vanyfing the result. You have to use the trick explained by Secret Doom in his web site (http:\\Batch.hpg.com.br FAQ #25).

2)
call cdul.bat result
should be anyway
call cdul.bat %result%

So stated to increment the date by one and get the next day is quite impossible to achieve via a batch script under plain DOS.


Report Offensive Follow Up For Removal

Response Number 2
Name: wizard-fred
Date: May 4, 2004 at 08:43:57 Pacific
Reply: (edit)

how about a simpler solution?

XCOPY C:\BATCH\*.* C:\UPLOAD /M

This will copy all new files to UPLOAD.

/M will set the archive bit so only new or changed files are copied.


Report Offensive Follow Up For Removal

Response Number 3
Name: Palsam
Date: May 5, 2004 at 04:53:12 Pacific
Reply: (edit)

IVO: Thanks for pointing out the errors in my code.

wizard-fred: Why not? Simpler is often better, and this solved my problem 100%. You saved my day :-) Thanks!



Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software