Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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$.batcall 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-TODAYRem 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.BATRem Copies Files based on Today's Date ("NUL" Hides Screen Messages)
XCOPY c:\batch\*.* C:\UPLOAD /D:%CUR-DATE% > NULGOTO END
Rem Copies Files based on The Date Given at the Command Line
:COPY-DATE
XCOPY c:\batch\*.* C:\UPLOAD /D:%1 /-YRem 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

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$.batThis 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.

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.

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!

![]() |
![]() |
![]() |

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