Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Find newest file

- - - - -

  • Please log in to reply
8 replies to this topic

#1
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
Hi, I'm looking for a way to process two or more files that will SET (pick up) the newest file
for %%# in (%*) do set newest |@copy newest ..(command)
Example between: %~dpn1.log and a named one %~dp1Default.log
If neither Exist abort command..


How to remove advertisement from MSFN

#2
5eraph

5eraph

    Update Packrat

  • MSFN Sponsor
  • 1,165 posts
  • Joined 04-July 05
  • OS:XP Pro x64
  • Country: Country Flag

Donator

Perhaps something like this...?

@ECHO OFF
SETLOCAL EnableDelayedExpansion
FOR /F "delims=" %%# IN ('DIR /A-D /B /OD "*.log" 2^>NUL') DO SET "sNewest=%%#"

Edited by 5eraph, 03 February 2013 - 10:47 PM.


#3
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

We need a little more information about the files you are using.

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

5eraph

    Update Packrat

  • MSFN Sponsor
  • 1,165 posts
  • Joined 04-July 05
  • OS:XP Pro x64
  • Country: Country Flag

Donator

I made the assumption based on sweept's consistent references to %1; this indicates the files are in the same folder. Continuing on the logic, since I have a bit more time now...

@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".

Edited by 5eraph, 04 February 2013 - 08:20 PM.


#5
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
As to newest I meant Newer ;) soo Sorry I need to check my vocabulary sometime!!!

The subroutine needs to pick\Find which one is newer by the file's time-stamp. Setting the latest one for the command ..

#6
5eraph

5eraph

    Update Packrat

  • MSFN Sponsor
  • 1,165 posts
  • Joined 04-July 05
  • OS:XP Pro x64
  • Country: Country Flag

Donator

Will there be only two files to compare?

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.

Edited by 5eraph, 04 February 2013 - 09:17 PM.


#7
Yzöwl

Yzöwl

    Wise Owl

  • Super Moderator
  • 4,557 posts
  • Joined 13-October 04
  • OS:Windows 7 x64
  • Country: Country Flag

Donator

The subroutine needs to pick\Find which one is newer by the file's time-stamp. Setting the latest one for the command ..

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
sweept

sweept

    Junior

  • Member
  • Pip
  • 70 posts
  • Joined 08-November 05
Thanks 5eraph I found what I needed now!
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 :)

Edited by sweept, 05 February 2013 - 06:19 AM.


#9
bphlpt

bphlpt

    MSFN Addict

  • Member
  • PipPipPipPipPipPipPip
  • 1,801 posts
  • Joined 12-May 07
  • OS:none specified
  • Country: Country Flag
And we learned absolutely nothing at all. Your secret is safe! :)

Cheers and Regards

Posted Image





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users