Jump to content
Sign in to follow this  
myspacee

Copy most recent file

Recommended Posts

hello,

i've a lan directory with a lot of .pdf

here are store all .pdf that we use to convert in .jpg for our site.

i must copy only most recent files but here i can found all versione of that file.

To explain post dir list example :

18/05/2008 19.44 3.069.437 IA1POM_1778318711.pdf

18/05/2008 20.03 1.138.747 IA1POM_1781584631.pdf

18/05/2008 20.38 1.140.245 IA1POM_1784850551.pdf

18/05/2008 20.55 1.139.187 IA1POM_1788116471.pdf

18/05/2008 20.56 1.140.567 IA1POM_1791382391.pdf

18/05/2008 20.57 1.140.369 IA1POM_1794648311.pdf

18/05/2008 21.51 7.754.130 IA1POM_1797914231.pdf

is there any way to copy most recent of them ? ( in my example IA1POM_1797914231.pdf)

I don't know what second part of name is, but i can suppose is progressive number .... i prefer to take date & time...

any idea ?

m.

Share this post


Link to post
Share on other sites

Use _DateDiff

The Date is: $date StringLeft($FileName,16)

Take the pasrts and Make it Compatible with StringMid :)


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Global $sDir, $hSearch, $sFilename, $sNewestFilename, $sNewestDate

$sDir = FileSelectFolder("Select directory", "")
If StringRight($sDir, 1) <> "\" Then $sDir &= "\"
$hSearch = FileFindFirstFile($sDir & "*.pdf")
If $hSearch = -1 Then
    MsgBox(0, "Error", "No .pdf files were found.")
    Exit
EndIf

While 1
    $sFilename = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    $sTemp = FileGetTime($sDir & $sFilename, 0, 1)
    If $sTemp > $sNewestDate Then
        $sNewestDate = $sTemp
        $sNewestFilename = $sFilename
    EndIf
WEnd

MsgBox(0, "Newest file", $sDir & $sNewestFilename)

Edited by zorphnog

Share this post


Link to post
Share on other sites

Here again, sorry.

Can't cicle this code in a do.while. i can't find error.

Post simple code to demonstrate that it return always first occurance of requested files

Global $sDir, $hSearch, $sFilename, $sNewestFilename, $sNewestDate


; FIRST step

$sDir = FileSelectFolder("Select directory", "")
If StringRight($sDir, 1) <> "\" Then $sDir &= "\"
$hSearch = FileFindFirstFile($sDir & "CATS*.pdf")     ;<------ search most recent file from list of   CATS*.pdf
If $hSearch = -1 Then
    MsgBox(0, "Error", "No .pdf files were found.")
    Exit
EndIf

While 1
    $sFilename = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    $sTemp = FileGetTime($sDir & $sFilename, 0, 1)
    If $sTemp > $sNewestDate Then
        $sNewestDate = $sTemp
        $sNewestFilename = $sFilename
    EndIf
WEnd

MsgBox(0, "Newest file", $sDir & $sNewestFilename)


; SECOND step

$hSearch = FileFindFirstFile($sDir & "DOGS*.pdf")            ;<------ search most recent file from list of   DOGS*.pdf
If $hSearch = -1 Then
    MsgBox(0, "Error", "No .pdf files were found.")
    Exit
EndIf

While 1
    $sFilename = FileFindNextFile($hSearch)
    If @error Then ExitLoop
    $sTemp = FileGetTime($sDir & $sFilename, 0, 1)
    If $sTemp > $sNewestDate Then
        $sNewestDate = $sTemp
        $sNewestFilename = $sFilename
    EndIf
WEnd

MsgBox(0, "Newest file", $sDir & $sNewestFilename)

can anyone help me to understand?

m.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...