Jump to content
Sign in to follow this  
ScriptMerchant

Copy by Ext and Modified date

Recommended Posts

:(

Hi guys,

Im trying to write a script that backs up data for a specifc file extension if the modified date is older than 7 days from current date. Im sort of stuck . Im trying to use the values returned for the date time as the file value to copy. Also Im having a problem with the corrrect syntax for While statements, any assitance would be greatly appreciated, here is what I have so far:

$search = FileFindFirstFile("c:\AutoCPyTest1\" & "*.doc")

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$FileDate = FileGetTime($search, 1) WEnd

if $iTodaysDate - $FileDate < 7 Then

CopyFile " $FileDate" "c:\P1TestCpy\ $FileDate"

$file = FileFindNextFile($search)

If @error Then ExitLoop

WEnd

; Close the search handle

FileClose($search)

Share this post


Link to post
Share on other sites

Need how your storing your date

should be able to use the _DateDiff User Defined function

here's your code cleaned up

Had an WEnd where it didn't belong

Was missing and EndIf

$search = FileFindFirstFile("c:\AutoCPyTest1\" & "*.doc")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $FileDate = FileGetTime($search, 1)
    If $iTodaysDate - $FileDate < 7 Then
        CopyFile " $FileDate" "c:\P1TestCpy\ $FileDate"
        
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
    EndIf
WEnd

; Close the search handle
FileClose($search)

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Need how your storing your date

should be able to use the _DateDiff User Defined function

here's your code cleaned up

Had an WEnd where it didn't belong

Was missing and EndIf

$search = FileFindFirstFile("c:\AutoCPyTest1\" & "*.doc")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $FileDate = FileGetTime($search, 1)
    If $iTodaysDate - $FileDate < 7 Then
        CopyFile " $FileDate" "c:\P1TestCpy\ $FileDate"
        
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
    EndIf
WEnd

; Close the search handle
FileClose($search)

<{POST_SNAPBACK}>

Hi frost

Sorry thought I included this here is how Im storing "Todays Date"

#include <Date.au3>

; Calculated the number of days since EPOCH (1900/01/01 00:00:00)

$iTodaysDate = _DateDiff( 'D',"1900/01/01 00:00:00",_NowCalc())

Share this post


Link to post
Share on other sites

I believe this is what your attempting to do

#include <Date.au3>

$iTodaysDate = _NowCalc()

$search = FileFindFirstFile("c:\AutoCPyTest1\*.doc")
; 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
    $FDate = FileGetTime($file, 1)
    $FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5]
    If _DateDiff('D', $FileDate, $iTodaysDate) > 7 Then
        FileCopy($file, "c:\P1TestCpy\" &  $file, 1)
    EndIf
WEnd

; Close the search handle
FileClose($search)
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

I believe this is what your attempting to do

#include <Date.au3>

$iTodaysDate = _NowCalc()

$search = FileFindFirstFile("c:\AutoCPyTest1\*.doc")
; 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
    $FDate = FileGetTime($file, 1)
    $FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5]
    If _DateDiff('D', $FileDate, $iTodaysDate) > 7 Then
        FileCopy($file, "c:\P1TestCpy\" &  $file, 1)
    EndIf
WEnd

; Close the search handle
FileClose($search)

<{POST_SNAPBACK}>

Hi, gafrost - thanks for the quick reply - Im getting the following error:

---------------------------

AutoIt Error

---------------------------

Line 18 (File "C:\FileCopyTemplate3Latest.au3"):

$FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5]

$FileDate = $FDate^ ERROR

Error: Subscript used with non-Array variable.

I tried modifying the line this way "$FileDate = $FDate" I also changed the FileGetTime flag to "0" for modified and changee the Diff to < 7 the script ran but the files it copied were up to a year old. Here is the current script:

#include <Date.au3>

$iTodaysDate = _NowCalc()

$search = FileFindFirstFile("c:\AutoCPyTest1\*.doc")

; 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

$FDate = FileGetTime($file, 0)

If _DateDiff('D', $FDate, $iTodaysDate) < 7 Then

FileCopy($file, "c:\P1TestCpy\" & $file, 1)

EndIf

WEnd

; Close the search handle

FileClose($search)

Edited by ScriptMerchant

Share this post


Link to post
Share on other sites

What I posted worked here

The following is from the help file for FileGetTime

Return Value

Success: Returns an array or string that contains the file time information. See Remarks.

Failure: Returns numeric 1 and sets @error to 1.

Remarks

The array is a single dimension array containing six elements:

$array[0]= year (four digits)

$array[1] = month (range 01 - 12)

$array[2] = day (range 01 - 31)

$array[3] = hour (range 00 - 23)

$array[4] = min (range 00 - 59)

$array[5] = sec (range 00 - 59)

Notice that return values are zero-padded.

Also noticed you keep checking for less than 7 days diff, you 1st post said more than 7 days, to me that would mean greater ">" than, instead of less "<" than. Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...