Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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 wrappingYou'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.batGot 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

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 itIn 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
:endIt 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

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 --

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

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