Sign in to follow this  
Followers 0
ksmith247

Another FileFindFirst/Next - FileGetTime question

4 posts in this topic

So I have looked at the help file and searched through the forum and find myself still scratching my head. Here is an idea of what I am trying to do

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("C:\*.txt")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $t = FileGetTime($file)

    $yyyymd = $t[0] & $t[1] & $t[2]

    If $yyyymd = @YEAR & @MON & @MDAY Then
        MsgBox(0, $t, "Same")
    Else
        MsgBox(0, $t, "Different " & $t)
    EndIf
WEnd

; Close the search handle
FileClose($search)

It's a mashup of FileFindFirst/Next and FileGetTime. I want to search a directory for files with a particular extension, then if found check the date. If the file was modified today I will copy it to another location (though above I just have a msgbox.) What am I missing? As always, thanks in advance.

It has been quite a while since I have posted, I like the new forum look.


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

Share this post


Link to post
Share on other sites



ksmith247,

The filegettime function is returning an error because you need to include the path to the file. You may want to add an eror checking routine after the function call.

Such as:

$t = FileGetTime('c:\' & $file)
    if $t = 0 then
        consolewrite('Error in filegettime for file = ' & $file & @lf)
        Exit
    endif

Good Luck,

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

So I have looked at the help file and searched through the forum and find myself still scratching my head. Here is an idea of what I am trying to do

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("C:\*.txt")

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $t = FileGetTime($file)

    $yyyymd = $t[0] & $t[1] & $t[2]

    If $yyyymd = @YEAR & @MON & @MDAY Then
        MsgBox(0, $t, "Same")
    Else
        MsgBox(0, $t, "Different " & $t)
    EndIf
WEnd

; Close the search handle
FileClose($search)

It's a mashup of FileFindFirst/Next and FileGetTime. I want to search a directory for files with a particular extension, then if found check the date. If the file was modified today I will copy it to another location (though above I just have a msgbox.) What am I missing? As always, thanks in advance.

It has been quite a while since I have posted, I like the new forum look.

#Include <Array.au3>

$TestArray = FileTimeCopy("E:\SourceDir","E:\DestDir","txt")
_ArrayDisplay($TestArray, "TestArray")

Func FileTimeCopy($SourceDir,$DestDir,$FileExtension,$FileCopyFlag = 8)
Local $TestArray[1] , $i = 0

if $FileExtension == "" Then $FileExtension = "*"
if StringRight($SourceDir,1) == "\" Then _
$SourceDir = StringTrimRight($SourceDir,1)
if StringRight($DestDir,1) == "\" Then _
$DestDir = StringTrimRight($DestDir,1)
if StringLeft($FileExtension,1) == "." Then _
$FileExtension = StringTrimLeft($FileExtension,1)

$search = FileFindFirstFile($SourceDir & "\*." & $FileExtension)
If $search = -1 Then _
Return SetError(1,0,0)

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $FileTime = FileGetTime($SourceDir & "\" & $file)
    $StrFileTim = $FileTime[0] & $FileTime[1] & $FileTime[2]

    $attrib = FileGetAttrib($SourceDir & "\" & $file)
    If Not StringInStr($attrib, "R") _
    And Not StringInStr($attrib, "S") _
    And Not StringInStr($attrib, "C") Then
    If $StrFileTim = @YEAR & @MON & @MDAY Then
    FileCopy ($SourceDir & "\" & $file ,$DestDir & "\" & $file,$FileCopyFlag)
    $i += 1
    ReDim $TestArray[$i][2]
    $TestArray[$i - 1][0] = $file
    $TestArray[$i - 1][1] = True
    Else
    $i += 1
    ReDim $TestArray[$i][2]
    $TestArray[$i - 1][0] = $file
    $TestArray[$i - 1][1] = False
    EndIf
    EndIf
WEnd

FileClose($search)
Return SetError(0,0,$TestArray)

EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

@kylomas - duh... I wish Jon would make AutoIt do what I want it to, not what I tell it to. Thank you.

@wolf9228 - Is there some advantage to undertaking this task in the manner you have described? I'm not opposed to it but it looks a bit confusing.


Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

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  
Followers 0