Jump to content

filemove...


Ravel
 Share

Recommended Posts

Does anyone know a simple code that has been written, or can be written that can assist me in moving files from one folder to another based on the date they were created? Specifically if they were created in the last day. I would only want hose files moved from the directory that they were created in, and placed in to a different folder for my review. Also can if someone could provide a visual que for me to see that it was accomplished. that would be helpful. thanks.

Link to comment
Share on other sites

@Ravel

Use FileMove and FileGetTime

Cheers, FireFox.

$t =  FileGetTime(@Windowsdir & "\Notepad.exe", 1)

If Not @error Then
    $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2]
    MsgBox(0, "Creation date of notepad.exe", $yyyymd)
EndIf

FileMove("C:\foo.au3", "D:\mydir\bak.au3")

; Second example:
;   uses flags '1' (owerwriting) and '8' (autocreating target dir structure) together
;   moves all txt-files from temp to txtfiles and prechecks if
;   target directory structure exists, if not then automatically creates it
FileMove(@TempDir & "\*.txt", @TempDir & "\TxtFiles\", 9)

Im not exactly sure how to get the output of Filegettime to work the way I want it to. I mean i can see that it will output the current date and time, but how do i get it to work using if,then, endif?

if filegettime; <----greater than the last time the script was run... meaning I have this script write to a txt log..appending it everytime I run the script, a date and time. Once those dates and times are written, it uses the latest date and time to determine how many new files were created since then. If there are files it then moves them, if there are not it does nothing. 
so the script would move to the 
Then filemove c:\blah\*.* to c:\blah\for review\*.*
else
endif

I am hoping someone can help me make heads or tails of this. thanks.

Edited by Ravel
Link to comment
Share on other sites

Here is some tested code for you to play with

;
$sFldr = @ScriptDir & "\"
$sFldr2 = @DeskTopDir & "\Test Folder\"
_FileMoveByDate($sFldr, $sFldr2)

Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, 1);; Migh be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        $iCount += 1
       ;; Consider using FileCopy($sPath & $sHold, $sNewPath & $sHold, 1) here.
        FileMove($sPath & $sHold, $sNewPath & $sHold, 1)
      EndIf
    Wend
  EndIf
  MsgBox(0, "Finished", $iCount & " files were moved")
  If $iCount > 0 Then ShellExecute($sNewPath)
EndFunc  ;<==> _FileMoveByDate()
;

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@Ravel

$time = FileGetTime("yourfile.ext")

;Then use $Time[0] to $Time[6]

Edit : @GeoSoft

Woosh ! The solution is there :)

Cheers, FireFox.

lol yea I just saw that too. getting ready to try that one out. thanks to you both. It looks like what I was trying to do.
Link to comment
Share on other sites

Here is some tested code for you to play with

;
$sFldr = @ScriptDir & "\"
$sFldr2 = @DeskTopDir & "\Test Folder\"
_FileMoveByDate($sFldr, $sFldr2)

Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, 1);; Migh be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        $iCount += 1
      ;; Consider using FileCopy($sPath & $sHold, $sNewPath & $sHold, 1) here.
        FileMove($sPath & $sHold, $sNewPath & $sHold, 1)
      EndIf
    Wend
  EndIf
  MsgBox(0, "Finished", $iCount & " files were moved")
  If $iCount > 0 Then ShellExecute($sNewPath)
EndFunc ;<==> _FileMoveByDate()
;
is this the way this should be written:

$sFldr = @ScriptDir & "C:\Users\webbdam\Documents\test\"; or should it be $sFldr = "C:\Users\webbdam\Documents\test\" 
$sFldr2 = @DeskTopDir & "C:\Users\webbdam\Documents\test\review\"; or $sFldr2 = "C:\Users\webbdam\Documents\test\review\" 
_FileMoveByDate($sFldr, $sFldr2)



Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, 1);; Migh be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        $iCount += 1
      ;; Consider using FileCopy($sPath & $sHold, $sNewPath & $sHold, 1) here.
        FileMove($sPath & $sHold, $sNewPath & $sHold, 1)
      EndIf
    Wend
  EndIf
  MsgBox(0, "Finished", $iCount & " files were moved")
  If $iCount > 0 Then ShellExecute($sNewPath)
EndFunc ;<==> _FileMoveByDate()
Link to comment
Share on other sites

lol yea I just saw that too. getting ready to try that one out. thanks to you both. It looks like what I was trying to do.

I was just coming back to edit that post so I'll put it here instead.

If you want to check for files created since a given date then call the function with last parameter using the format YYYYMMDD

Example, this will get the files created since yesterday.

$sMovDate = @Year & @Mon & $mDay-1
_FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@GeoSoft

What about add hour and min ?

Cheers, FireFox.

Could do it that way as well. As long as it ends up being a number that can be checked by If $iCreated >= $iDate

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$sMovDate = @Year & @Mon & $mDay-1<---- is this just the current date (automatic) meaning it will alwas call the current date as it is when I run the script? Thats the way I understand it just trying to be clear. before I run any scripts (gov't pc)

_FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate)

Edited by Ravel
Link to comment
Share on other sites

is this the way this should be written:

$sFldr = @ScriptDir & "C:\Users\webbdam\Documents\test\"; or should it be $sFldr = "C:\Users\webbdam\Documents\test\"

$sFldr2 = @DeskTopDir & "C:\Users\webbdam\Documents\test\review\"; or $sFldr2 = "C:\Users\webbdam\Documents\test\review\"

_FileMoveByDate($sFldr, $sFldr2)

"C:\Users\webbdam\Documents\test\"

and

"C:\Users\webbdam\Documents\test\review\"

I just used the folder macros for testing

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

"C:\Users\webbdam\Documents\test\"

and

"C:\Users\webbdam\Documents\test\review\"

I just used the folder macros for testing

Ok cool thanks. I kinda figured it was supposed to be that way. Just wanted to be sure prior to running the script since this is a gov't PC.

Link to comment
Share on other sites

Ok cool thanks. I kinda figured it was supposed to be that way. Just wanted to be sure prior to running the script since this is a gov't PC.

I have no objection to messing up gov't equipment.

Also don't forget that for $sPattern I just used the wildcard for any file/folder You could change that by passing it a given file pattern.

_FileMoveByDate($sFldr, $sFldr2, "*.au3")

Would get all the au3 files in the folder.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

im getting the following error:

>"C:\Users\webbdam\Documents\AutoIt\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\webbdam\Desktop\desktop stuff\Scripts\filereview.au3"

C:\Users\webbdam\Desktop\desktop stuff\Scripts\filereview.au3 (21) : ==> Subscript used with non-Array variable.:

$iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]

$iCreated = $aCreated^ ERROR

>Exit code: 1 Time: 0.522

syntax check in scite passes, but it fails when run. Im still working to see what I did wrong, but as of this moment Im not sure.

oh sorry this is the full code i have atm:

$sFldr = "C:\Users\webbdam\Documents\test\" 
$sFldr2 = "C:\Users\webbdam\Documents\test\review\"

$sMovDate = 20090107 -1
_FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate)



Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, 1);; Migh be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        $iCount += 1
    ;; Consider using FileCopy($sPath & $sHold, $sNewPath & $sHold, 1) here.
        FileMove($sPath & $sHold, $sNewPath & $sHold, 1)
      EndIf
    Wend
  EndIf
  MsgBox(0, "Finished", $iCount & " files were moved")
  If $iCount > 0 Then ShellExecute($sNewPath)
EndFunc;<==> _FileMoveByDate()
Edited by Ravel
Link to comment
Share on other sites

im getting the following error:

syntax check in scite passes, but it fails when run. Im still working to see what I did wrong, but as of this moment Im not sure.

oh sorry this is the full code i have atm:

$sFldr = "C:\Users\webbdam\Documents\test\" 
$sFldr2 = "C:\Users\webbdam\Documents\test\review\"

$sMovDate = 20090107 -1
_FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate)



Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, 1);; Migh be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        $iCount += 1
;; Consider using FileCopy($sPath & $sHold, $sNewPath & $sHold, 1) here.
        FileMove($sPath & $sHold, $sNewPath & $sHold, 1)
      EndIf
    Wend
  EndIf
  MsgBox(0, "Finished", $iCount & " files were moved")
  If $iCount > 0 Then ShellExecute($sNewPath)
EndFunc;<==> _FileMoveByDate()
Just give me a few minutes to look at it and I'll get back to you. Busy with a client at the moment.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

okay I rewrote it for inclusion in my Filex.au3 UDF and here is what I have now. The test I used is below. If it fails then let me know what the returned error was. It now has the option to move or copy the files. Read the parameters in the header.

;
;===============================================================================
; Function Name:   _FileMoveByDate()
; Description:   Use to move or copy files by date created
; Syntax:         _FileMoveByDate($sPath, $sNewPath[, $sPattern = "*"[, $iDate = -1[, $iDateFlag = 1[, $iMove = 1[, $iOverWrite = 1]]]]])
; Parameter(s): $sPath - the folder to search
;                 $sNewPath - The folder where the files should be moved/copied to
;                 $sPattern - File search pattern.  Default is all
;                 $iDate (optional) - The date to start checking in the format YYYMMDD. Default is current day
;                 $iDateFlag (optional)- see FileGetTime() for possible values,  Default is 0 (Last Modified)
;                 $iMove (optional) - If not 1 then a copy operation will be performed instead of a move
;                 $iOverWrite (optional) - If 1 (default) then an existing file of the same name will be over-written
; Requirement(s):  
; Return Value(s): - Success - Returns the count of files copied or moved
;                 - Failure - Sets @Error to
;                                  1 - If no files match the pattern
;                                  2 - If the source folder path does not exist
;                                  3 - if unable to create the destination folder
; Author(s):       GEOSoft
; Modification(s): 
; Note(s):  
; Example(s):   
#cs
   $sFldr = @ScriptDir & "\"
   $sFldr2 = @DeskTopDir & "\Test Folder\"
   $iMoved = _FileMoveByDate($sFldr, $sFldr2)
   If NOT @Error Then
      MsgBox(0, "Finished", $iMoved & " files were moved or copied")
      If $iMoved Then ShellExecute($sFldr2)
   EndIf
#ce
;===============================================================================

Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1, $iDateFlag = 0, $iMove = 1, $iOverWrite = 1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If StringRight($sPath, 1) <> "\" Then $sPath &= "\"
  If NOT FileExists($sPath) Then Return SetError(2)
  If StringRight($sNewPath, 1) <> "\" Then $sNewPath &= "\"
  If $iDateFlag > 2 OR $iDateFlag < 0 Then $iDateFlag = 1
  If NOT FileExists($sNewPath) Then
   If NOT DirCreate($sNewPath) Then Return SetError(3)
  EndIf
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
    If $iOverWrite <> 1 Then $iOverWrite = 0
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, $iDateFlag);; Might be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        If $iMove = 1 Then
         If NOT FileMove($sPath & $sHold, $sNewPath & $sHold, $iOverWrite) Then
            MsgBox(4096, "File Error", "Unable to Move The File " & $sHold)
            ContinueLoop
         EndIf
        Else
         If NOT FileCopy($sPath & $sHold, $sNewPath & $sHold, $iOverWrite) Then
            MsgBox(4096, "File Error", "Unable to Copy The File " & $sHold)
            ContinueLoop
         EndIf
        EndIf
        $iCount += 1
      EndIf
    Wend
  Else
   Return SetError(1)
  EndIf
  Return $iCount
EndFunc  ;<==> _FileMoveByDate()
;

Example usage using copy mode instead of move.

;
$sFldr = @ScriptDir & "\"
$sFldr2 = @DeskTopDir & "\Test Folder\"
$sMovDate = 20090107 -1
$iMoved = _FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate, 1, 0)
If NOT @Error Then
   MsgBox(0, "Finished", $iMoved & " files were moved or copied")
   If $iMoved Then ShellExecute($sFldr2)
Else
   MsgBox(0, "Error", "The error returned was " & @Error)
EndIf
;

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

okay I rewrote it for inclusion in my Filex.au3 UDF and here is what I have now. The test I used is below. If it fails then let me know what the returned error was. It now has the option to move or copy the files. Read the parameters in the header.

;
;===============================================================================
; Function Name:   _FileMoveByDate()
; Description:   Use to move or copy files by date created
; Syntax:         _FileMoveByDate($sPath, $sNewPath[, $sPattern = "*"[, $iDate = -1[, $iDateFlag = 1[, $iMove = 1[, $iOverWrite = 1]]]]])
; Parameter(s): $sPath - the folder to search
;                 $sNewPath - The folder where the files should be moved/copied to
;                 $sPattern - File search pattern.  Default is all
;                 $iDate (optional) - The date to start checking in the format YYYMMDD. Default is current day
;                 $iDateFlag (optional)- see FileGetTime() for possible values,  Default is 0 (Last Modified)
;                 $iMove (optional) - If not 1 then a copy operation will be performed instead of a move
;                 $iOverWrite (optional) - If 1 (default) then an existing file of the same name will be over-written
; Requirement(s):  
; Return Value(s): - Success - Returns the count of files copied or moved
;                 - Failure - Sets @Error to
;                                  1 - If no files match the pattern
;                                  2 - If the source folder path does not exist
;                                  3 - if unable to create the destination folder
; Author(s):       GEOSoft
; Modification(s): 
; Note(s):  
; Example(s):   
#cs
   $sFldr = @ScriptDir & "\"
   $sFldr2 = @DeskTopDir & "\Test Folder\"
   $iMoved = _FileMoveByDate($sFldr, $sFldr2)
   If NOT @Error Then
      MsgBox(0, "Finished", $iMoved & " files were moved or copied")
      If $iMoved Then ShellExecute($sFldr2)
   EndIf
#ce
;===============================================================================

Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1, $iDateFlag = 0, $iMove = 1, $iOverWrite = 1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If StringRight($sPath, 1) <> "\" Then $sPath &= "\"
  If NOT FileExists($sPath) Then Return SetError(2)
  If StringRight($sNewPath, 1) <> "\" Then $sNewPath &= "\"
  If $iDateFlag > 2 OR $iDateFlag < 0 Then $iDateFlag = 1
  If NOT FileExists($sNewPath) Then
   If NOT DirCreate($sNewPath) Then Return SetError(3)
  EndIf
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
    If $iOverWrite <> 1 Then $iOverWrite = 0
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, $iDateFlag);; Might be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        If $iMove = 1 Then
         If NOT FileMove($sPath & $sHold, $sNewPath & $sHold, $iOverWrite) Then
            MsgBox(4096, "File Error", "Unable to Move The File " & $sHold)
            ContinueLoop
         EndIf
        Else
         If NOT FileCopy($sPath & $sHold, $sNewPath & $sHold, $iOverWrite) Then
            MsgBox(4096, "File Error", "Unable to Copy The File " & $sHold)
            ContinueLoop
         EndIf
        EndIf
        $iCount += 1
      EndIf
    Wend
  Else
   Return SetError(1)
  EndIf
  Return $iCount
EndFunc ;<==> _FileMoveByDate()
;

Example usage using copy mode instead of move.

;
$sFldr = @ScriptDir & "\"
$sFldr2 = @DeskTopDir & "\Test Folder\"
$sMovDate = 20090107 -1
$iMoved = _FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate, 1, 0)
If NOT @Error Then
   MsgBox(0, "Finished", $iMoved & " files were moved or copied")
   If $iMoved Then ShellExecute($sFldr2)
Else
   MsgBox(0, "Error", "The error returned was " & @Error)
EndIf
;

sorry i was just able to get this. It looks great. I'm gonna give it a shot here in a min. I'll let you know Thanks.

Link to comment
Share on other sites

Im still getting that same error mentioned above, I must be doing something wrong. here is the code that I am using:

#include <Filex.au3>
$sFldr = "C:\Users\webbdam\Documents\AutoIt\Scripts\Test" 
$sFldr2 = "C:\Users\webbdam\Documents\AutoIt\Scripts\Test\review\"


$sMovDate = 20090107 -1
$iMoved = _FileMoveByDate($sFldr, $sFldr2, "*", $sMovDate, 1, 0)
If NOT @Error Then
   MsgBox(0, "Finished", $iMoved & " files were moved or copied")
   If $iMoved Then ShellExecute($sFldr2)
Else
   MsgBox(0, "Error", "The error returned was " & @Error)
EndIf

Func _FileMoveByDate($sPath, $sNewPath, $sPattern = "*", $iDate = -1, $iDateFlag = 0, $iMove = 1, $iOverWrite = 1)
  Local $sHold, $aCreated, $iCreated, $iCount = 0
  If StringRight($sPath, 1) <> "\" Then $sPath &= "\"
  If NOT FileExists($sPath) Then Return SetError(2)
  If StringRight($sNewPath, 1) <> "\" Then $sNewPath &= "\"
  If $iDateFlag > 2 OR $iDateFlag < 0 Then $iDateFlag = 1
  If NOT FileExists($sNewPath) Then
   If NOT DirCreate($sNewPath) Then Return SetError(3)
  EndIf
  If $iDate = -1 Then $iDate = @Year & @Mon & @mDay
  $sFile = FileFindFirstFile($sPath & $sPattern)
  If NOT @Error Then
    If NOT FileExists($sNewPath) Then DirCreate($sNewPath)
    If $iOverWrite <> 1 Then $iOverWrite = 0
    While 1
      $sHold = FileFindNextFile($sFile)
      If @Error Then ExitLoop
      If StringInStr(FileGetAttrib($sHold), "D") Then ContinueLoop
      $aCreated = FileGetTime($sHold, $iDateFlag);; Might be better to use the 0 (modified) flag here
      $iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2]
      If $iCreated >= $iDate Then
        If $iMove = 1 Then
         If NOT FileMove($sPath & $sHold, $sNewPath & $sHold, $iOverWrite) Then
            MsgBox(4096, "File Error", "Unable to Move The File " & $sHold)
            ContinueLoop
         EndIf
        Else
         If NOT FileCopy($sPath & $sHold, $sNewPath & $sHold, $iOverWrite) Then
            MsgBox(4096, "File Error", "Unable to Copy The File " & $sHold)
            ContinueLoop
         EndIf
        EndIf
        $iCount += 1
      EndIf
    Wend
  Else
   Return SetError(1)
  EndIf
  Return $iCount
EndFunc;<==> _FileMoveByDate()

Any ideas?

Edited by Ravel
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...