Jump to content

filemove...


Ravel
 Share

Recommended Posts

Dd it return an actual error? The backslash shouldn't make any difference.

Are you positive that the files in question were CREATED since Jan 06 2009?

Is this actually failing when you run the script or only when Run it in Scite?

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

Dd it return an actual error? The backslash shouldn't make any difference.

Are you positive that the files in question were CREATED since Jan 06 2009?

Is this actually failing when you run the script or only when Run it in Scite?

I am not sure what you are referring to. Created since jan 6 2009? which files? It fails when I run the script. When I do the syntax check in scite it passes.

In that code above I included Filex.au3 in the script (it was failing before I included filex.au3), but it did not solve the problem. here is the error:

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

C:\Users\webbdam\Documents\AutoIt\Scripts\filereview.au3 (34) : ==> Subscript used with non-Array variable.:

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

$iCreated = $aCreated^ ERROR

>Exit code: 1 Time: 1.110

Edited by Ravel
Link to comment
Share on other sites

I am not sure what you are referring to. Created since jan 6 2009? which files? It fails when I run the script. When I do the syntax check in scite it passes.

In that code above I included Filex.au3 in the script (it was failing before I included filex.au3), but it did not solve the problem. here is the error:

It there are no files that match the date criteria it will fail with that exact error. Let me take another look at it later today. In the meantime I said that I rewote it for inclusion in Filex.au3 but I have not uploaded the current version yet so unless there you are using other functions in that UDF there is no need to #include it.

Scite shows no syntax errors because there are none. It's failing because there are no matching files when you run it so the array can not be created. Simple error check for that.

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

It there are no files that match the date criteria it will fail with that exact error. Let me take another look at it later today. In the meantime I said that I rewote it for inclusion in Filex.au3 but I have not uploaded the current version yet so unless there you are using other functions in that UDF there is no need to #include it.

Scite shows no syntax errors because there are none. It's failing because there are no matching files when you run it so the array can not be created. Simple error check for that.

Ok. Cool. I am not sure if there is something that I need to do, or if there is something that you are going to check. Is there a way to have it run regardless even if some of the data is incorrect? Or what do i need to ensure that I put in the script to make sure that it will pass? Is that the date? Do I need to ensure that there are files in the folder that match the date that I am searching for to keep it from failing?

Link to comment
Share on other sites

Ok. Cool. I am not sure if there is something that I need to do, or if there is something that you are going to check. Is there a way to have it run regardless even if some of the data is incorrect? Or what do i need to ensure that I put in the script to make sure that it will pass? Is that the date? Do I need to ensure that there are files in the folder that match the date that I am searching for to keep it from failing?

According to your last reply it's FileGetTime() Thats failing and I can't see why. Could you change the function to this for testing please?

;
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
      If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & $aCreated)
      $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()
;

If that extra MsgBox pops up then, before you click ok, press Ctrl+C and paste the results into a reply.

Thanks

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

According to your last reply it's FileGetTime() Thats failing and I can't see why. Could you change the function to this for testing please?

;
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
      If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & $aCreated)
      $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()
;

If that extra MsgBox pops up then, before you click ok, press Ctrl+C and paste the results into a reply.

Thanks

---------------------------
ERROR TEST
---------------------------
review




---------------------------
OK   
---------------------------

Thats what you were looking for right?

Link to comment
Share on other sites

---------------------------
ERROR TEST
---------------------------
review




---------------------------
OK   
---------------------------

Thats what you were looking for right?

Now I can see whats happening and I know whats causing it. I can fix it but I need you to do one more test. Change the line

If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & $aCreated)

To

If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & FileGetAttrib($sHold))

and then post the results again (same as the last test). We may have just found a minor bit of a bug. I can fix it with a regexp regardless. I just want to know why it failed at all.

BTW: What version of AutoIt are you using?

Edit: Will these files all have the same extension by any chance? If they do then it should work just by calling the function with the third parameter set "*.<file extension>"

Example "*.txt" for text files

Edited by GEOSoft

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

Now I can see whats happening and I know whats causing it. I can fix it but I need you to do one more test. Change the line

If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & $aCreated)

To

If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & FileGetAttrib($sHold))

and then post the results again (same as the last test). We may have just found a minor bit of a bug. I can fix it with a regexp regardless. I just want to know why it failed at all.

BTW: What version of AutoIt are you using?

Edit: Will these files all have the same extension by any chance? If they do then it should work just by calling the function with the third parameter set "*.<file extension>"

Example "*.txt" for text files

k here is what I found...

---------------------------
ERROR TEST
---------------------------
review




---------------------------
OK   
---------------------------

;-------------------------------
>"C:\Users\webbdam\Documents\AutoIt\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\webbdam\Documents\AutoIt\Scripts\filereview.au3"   
C:\Users\webbdam\Documents\AutoIt\Scripts\filereview.au3 (36) : ==> Subscript used with non-Array variable.: 
$iCreated = $aCreated[0] & $aCreated[1] & $aCreated[2] 
$iCreated = $aCreated^ ERROR
>Exit code: 1   Time: 2.244
;-------------------------------

Full Code

$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
      If NOT IsArray($aCreated) Then MsgBox(4096, "ERROR TEST", $sHold & @CRLF & @CRLF & FileGetAttrib($sHold))
      $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()
;

I'm still getting that error... Pertaining to the version, I am running it directly from scite (i cant install autoit on gov't pc) but the scite version is: 1.71, it came from the auto it package: 3.2.8.1.

The files aren't all the same (PDF, TXT, DOC, DOCX).

Do you think that the problem could be that I couldn't install autoit? I mean I can use the exe's such as the window info exe, scite, and any exe's built on a pc that has the auto it installed.

Edited by Ravel
Link to comment
Share on other sites

Damn stupid error !!! This should fix it

;
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
      $sHold = $sPath & $sHold
      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($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()
;

Sorry about that.

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

Damn stupid error !!! This should fix it

;
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
      $sHold = $sPath & $sHold
      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($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()
;

Sorry about that.

hmm... i just attempted to use it and i got an error stating that it is unable to copy the file? what does that mean?

---------------------------
File Error
---------------------------
Unable to Copy The File C:\Users\webbdam\Documents\AutoIt\Scripts\Test\POWER OUT USING SPECAN.doc
---------------------------
OK   
---------------------------
Edited by Ravel
Link to comment
Share on other sites

hmm... i just attempted to use it and i got an error stating that it is unable to copy the file? what does that mean?

---------------------------
File Error
---------------------------
Unable to Copy The File C:\Users\webbdam\Documents\AutoIt\Scripts\Test\POWER OUT USING SPECAN.doc
---------------------------
OK   
---------------------------
It means we got past the initial error for starters. That's a good thing I think.

Now for the current issue.

Did any files get copied or was that the first file?

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

Geo... were you still lookin over this?

I've been jammed here with a couple of projects. I'll look at it again later today. Still can't see what's wrong. It worked fine for me.

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

  • 2 months later...

If anyone is still following this thread, I finally found time to fix the bug. Just a typical Noob file path error.

The new code is posted on my site and the download of FileX.au3 can be found here.

http://dundats.mvps.org/AutoIt/files/filex.zip

Please note that I also changed the function name from _FileMoveByDate () to _File_MoveByDate()

I have also added a new parameter which allows you to copy/move files >= date or <= date so it can be used to copy/move files that are ready for archiving.

Edited by GEOSoft

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

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