Computing.Net > Forums > Disk Operating System > Batch File Programming

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.

Batch File Programming

Reply to Message Icon

Name: Reginald Marbebe
Date: July 10, 2001 at 03:42:17 Pacific
Comment:

Is there a way where I can copy only the latest file(s) in a directory? I've been looking for a possible solution for a long time now. I hope somebody will answer me....

Thanks a lot



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: July 10, 2001 at 12:33:40 Pacific
Reply:

The time for your answer has come! :D
Yes, that can be done (not too easy =])
Watch this sample, it will copy all files from current directory that were modifyed at the current day (they will be copyed to c:\data)

This one will only work on an english dos
The numbers aren't part of it, they're just to help with the line wrapping

You'll need EDLIN.exe. I have sended it to your mail. (as well as these other two files below)
You should put:
EDLIN.EXE - at a directory path, such as c:\windows
DATECOPY.BAT - at the directory where the files to by copyed are
DATECOPY.REP - at c:\
(Of course all that can be changed)

contents of datecopy.bat:

1. @echo off
2. SET TR=
3. SET DATE2=
4. echo. |date |find /i "Current"> out.bat
5. echo SET DATE=%%4> current.bat
6. call out.bat
7. echo SET DATE=%DATE%> out.bat
8. edlin out.bat < c:\datecopy.rep > nul
9. call out.bat
10. echo ; |choice /c:;%date%; call current.bat,>out.bat
11. echo :loop> current.bat
12. echo IF "%%1"=="[" SHIFT>> current.bat
13. echo IF "%%1"=="]?" GOTO end>> current.bat
14. echo IF "%%1"=="-" SET TR=%%TR%%]>> current.bat
15. echo IF "%%TR%%"=="]]" SHIFT>> current.bat
16. echo IF "%%TR%%"=="]]" SHIFT>> current.bat
17. echo IF "%%TR%%"=="]]" SHIFT>> current.bat
18. echo IF "%%TR%%"=="]]" SET TR=>> current.bat
19. echo IF NOT "%%1"=="-" SET DATE2=%%DATE2%%,%%1>> current.bat
20. echo SHIFT>> current.bat
21. echo GOTO loop>> current.bat
22. echo :end>> current.bat
23. call out.bat
24. echo SET DATE=%%1%%2/%%3%%4/%%5%%6> current.bat
25. call current.bat%date2%
26. dir |find /n "%date%"> out.bat
27. edlin out.bat < c:\datecopy.rep > nul
28. echo COPY %%2.%%3 C:\DATA> current.bat
29. call out.bat
30. SET DATE=
31. SET DATE2=


contents of datecopy.rep:

1,#r/^Z-
1,#r[^Zcall current.bat,
1,#r]^Z,
e


NOTE: ^Z means ctrl+z character. You may get it on dos edit by CTRL+P+Z
NOTE2: datecopy.rep must be on c:\
NOTE3: This were designed to a computer that has the dos date separator "/" ie: "MM/DD/YYYY". If your dos has as separator "-" (ie: "MM-DD-YYYY"), you must do these alterations:
take out line 8 (optional)
replace line 24 for: (all the same line)
echo SET DATE=%%1%%2-%%3%%4-%%5%%6> current.bat

Got it?
Not quite simple, hum? Yeah... And that's if you want to copy the ones modifyed today. If you want to copy the ones modifyed lets say in the last 5 days, it gets even more complicated
But it's possible, dont worry.

Was that what you wanted? I'll be glad to help any furhter =]

Please keep me informed!!

-- Secret_Doom --

email: secret_doom@hotmail.com


0

Response Number 2
Name: Secret_Doom
Date: July 10, 2001 at 12:44:10 Pacific
Reply:

PS: Thanks to LAURENCE SOUCY for the help with the lines 10 to 22 of datecopy.bat


0

Response Number 3
Name: Secret_Doom
Date: July 13, 2001 at 23:15:48 Pacific
Reply:

AAAAAAAAAH!!!!
What a crap I posted above!!! FORGET MY TWO LAST POSTS!

I hadn't noticed the /d switch at xcopy
I'm terribly sorry (again!)
Sorry about all that Reginald!
You said something about /d switch and I didn't even think about it... Now I see it

In the last mail you sent to me, you said you wanted a batch to check for updates and copy them. Here a way of doing that:
(english dos)

::update.bat
@echo off
call c:\data\getdate.bat
if not "%date%"=="" goto ok
echo Type in last update date:
fc con nul /lb1 /n |date |find "1:"> out.bat
echo SET DATE=%%5> enter.bat
call out.bat
del enter.bat
if "%date%"=="" goto end
:ok
xcopy /d:%date% *.* c:\data
echo. |date |find "Current"> out.bat
echo SET DATE=%%4> current.bat
call out.bat
echo SET DATE=%DATE%> c:\data\getdate.bat
del out.bat
del current.bat
:end

It will copy all files from current directory to c:\data that were modifyed on or later then the date of the last run of the batch.

That should do it. At the fisrt time you run it, it will ask you for the date of last update. But it will only do it on the first time you run it.
It will create a temporary file - c:\data\getdate.bat - that must not be deleted (it contains the date of last update)

THAT should solve your problem!
Please keep me informed!
Sorry again by the mess

-- Secret_Doom --

email: secret_doom@hotmail.com


0

Response Number 4
Name: Secret_Doom
Date: July 13, 2001 at 23:32:23 Pacific
Reply:

IMPORTANT NOTE: The date must be typed within separators (MM/DD/YYYY)

It would even better to change following line from batch:
echo Type in last update date:

for

echo Type in last update date: mm/dd/yyyy

-- Secret_Doom --


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 Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch File Programming

MSDOS batch file program www.computing.net/answers/dos/msdos-batch-file-program/2471.html

Help batch file programming www.computing.net/answers/dos/help-batch-file-programming/14554.html

DOS batch file programming www.computing.net/answers/dos/dos-batch-file-programming/8142.html