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
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?
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
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.
Summary: How can I use a batch file on XP Pro to check if ANY file in a directory (including any subdirectories) has been modified in the last 24 hours? If so, I want to run a zip command on the top-level dire...
Summary: I plan on running the batch as a scheduled job every hour on a server to check for files being created over a certain size. If the size is too large it will notify an admin. Hello from WSU...
Summary: Hi all - Need a little help. Attempting to write a batch file to check for and delete multiple files, outputting to a log file after anything is found. Here's what I have so far: echo off setLocal...