Computing.Net > Forums > Programming > batch to check last modified file

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 to check last modified file

Reply to Message Icon

Name: dave19
Date: March 28, 2008 at 19:05:11 Pacific
OS: WinXP SP2
CPU/Ram: 512
Comment:

Hi, I need a batch file to check last modified file in folder and copy it another specified place. is there any command to check last modified or new date out of files?



Sponsored Link
Ads by Google

Response Number 1
Name: devil_himself
Date: March 28, 2008 at 20:19:34 Pacific
Reply:

@echo off
setlocal
set srcDir=C:\Source
set destdir=c:\dest
set lastmod=
pushd "%srcDir%"
for /f "tokens=*" %%a in ('dir /b /od 2^>NUL') do set lastmod=%%a
if "%lastmod%"=="" echo Could not locate files.&goto :eof
copy "%lastLog%" "%destDir%"


0

Response Number 2
Name: dave19
Date: March 28, 2008 at 21:24:04 Pacific
Reply:

Thanks! in the last line i believe its %logmod%


0

Response Number 3
Name: devil_himself
Date: March 28, 2008 at 23:42:13 Pacific
Reply:

Yes ..


0

Response Number 4
Name: devil_himself
Date: March 28, 2008 at 23:42:58 Pacific
Reply:

No ... Not %logmod% Its %lastmod%


0

Response Number 5
Name: dave19
Date: March 29, 2008 at 00:31:14 Pacific
Reply:

Thanks, it works fine as it should..
how do ('dir /b /od 2^>NUL') works?


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: March 29, 2008 at 01:34:52 Pacific
Reply:

more simply:

::=======
@echo off

for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d') do (
copy %%a d:\mystuff & goto :eof)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: dave19
Date: March 29, 2008 at 05:31:41 Pacific
Reply:

Thanks much M2, i got it clearly now :)


0

Response Number 8
Name: dave19
Date: March 29, 2008 at 06:53:47 Pacific
Reply:

a little doubt, would %%a copy the first line?


0

Response Number 9
Name: Mechanix2Go
Date: March 30, 2008 at 01:08:36 Pacific
Reply:

not clear


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 10
Name: dave19
Date: March 30, 2008 at 02:35:02 Pacific
Reply:

yeah after i tried to understand it.


0

Response Number 11
Name: klint
Date: March 30, 2008 at 13:55:11 Pacific
Reply:

If you are asking about M2's code

for /f "tokens=* delims= " %%a in ('dir/b/a-d/o-d') do (
copy %%a d:\mystuff & goto :eof)

The directory is listed in reverse chronological order (most recent first) and as soon as the first (i.e. most recent) file is copied, the loop exits using goto.


0

Sponsored Link
Ads by Google
Reply to Message Icon






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: batch to check last modified file

batch file to check modified date www.computing.net/answers/programming/batch-file-to-check-modified-date/12915.html

Batch to scan for new files www.computing.net/answers/programming/batch-to-scan-for-new-files/14489.html

Bat file to check for multiple files www.computing.net/answers/programming/bat-file-to-check-for-multiple-files/19129.html