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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Win2k batch: copy only new files?

Reply to Message Icon

Name: Palsam
Date: May 4, 2004 at 05:36:50 Pacific
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



Sponsored Link
Ads by Google

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

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.


0

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

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.


0

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

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!



0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: Win2k batch: copy only new files?

Copy only newely added files www.computing.net/answers/programming/copy-only-newely-added-files/16891.html

Batch copy files on txt file incl. subdir. www.computing.net/answers/programming/batch-copy-files-on-txt-file-incl-subdir/20053.html

Copy only first file in a series www.computing.net/answers/programming/copy-only-first-file-in-a-series/16718.html