Find newest file batch
#1
Posted 03 February 2013 - 08:16 PM
for %%# in (%*) do set newest |@copy newest ..(command)
Example between: %~dpn1.log and a named one %~dp1Default.log
If neither Exist abort command..
#2
Posted 03 February 2013 - 10:42 PM
@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR /F "delims=" %%# IN ('DIR /A-D /B /OD "*.log" 2^>NUL') DO SET "sNewest=%%#"
This post has been edited by 5eraph: 03 February 2013 - 10:47 PM
#3
Posted 04 February 2013 - 03:06 AM
5eraph has assumed you are using the newest file of every file of a certain type in the same directory.
If you were copying that file then the following would probably suffice
XCOPY *.log X:\DestinationDir /D /Y
#4
Posted 04 February 2013 - 07:13 PM
@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR /F "delims=" %%# IN ('DIR /A-D /B /OD "%~dp1*.log" 2^>NUL') DO SET "sNewest=%%#"
IF EXIST "%~dp1Default.log" (
IF /I "!sNewest!"=="%~n1.log" (
COPY "%~dpnx1"
(command)
) )
I have made two further assumptions:
- The desired code is either a packaged function or standalone script that takes only one parameter (%1).
- "%~dpn1.log" has the same timestamp as "%1".
This post has been edited by 5eraph: 04 February 2013 - 08:20 PM
#5
Posted 04 February 2013 - 08:27 PM
The subroutine needs to pick\Find which one is newer by the file's time-stamp. Setting the latest one for the command ..
#6
Posted 04 February 2013 - 08:33 PM
How do "%~dpn1.log" and "%~dp1Default.log" fit into the picture?
- Will there be a "%2"?
- How are parameters (%1, %2, etc.) passed to the script: "drag-and-drop," or passed from another script?
Will the files to compare always be in the same directory?
Which command? As Yzöwl stated previously, a simple method may exist through that command.
This post has been edited by 5eraph: 04 February 2013 - 09:17 PM
#7
Posted 05 February 2013 - 12:01 AM
sweept, on 04 February 2013 - 08:27 PM, said:
I think this answers a few questions!
You have created your own secret batch file which calls a subroutine, written by us, which is passed two parameters. The subroutine must set a variable or return for the most recently modified/accessed/created, (we haven't been told), in order that your secret batch file can continue on its own way without bothering us!
Just post the batch file you have and let us play with it as necessary!
#8
Posted 05 February 2013 - 06:17 AM
at first glance I couldn't figure whats achieved using a dir command ..That /od switch (cool)
that was one great vast example
Thanks again!!! & to youYzöwl &members viewing thanks for you's patience
This post has been edited by sweept: 05 February 2013 - 06:19 AM
#9
Posted 05 February 2013 - 12:28 PM
Cheers and Regards
- ← Batch file and UAC in Windows 7 ?
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Recover open windows (explorer) →



Help
Back to top









