Jump to content
Sign in to follow this  
jaberwacky

[Solved] Problem with FileMove()

Recommended Posts

jaberwacky

Good morning

I have an issue with FileMove. Seems it doesn't want to work anymore. Just wants to lie about the house and expect to get fed. While it's older and more studious brother, FileCopy(), realizes the importance of doing as it is told.

lulz, It's 2:30 in the am here, sorry...

FileCopy() works just fine and FileMove() used to work just fine! Nothing has changed except for maybe the trout that swims in the same river. Another day has passed. And death still looms o'er the horizon.

I used FileSetAttrib() to change it from read-only and all other manner of RASHNOT combos. I tried to FileCopy() the files that I wanted to move and then FIleDelete() them afterwards. FileDelete refuses to touch these files. Seems to work on other files!

I use ImageMagickObject in my script. Could there be some sort of a lock on my filez? Well, no I doubt it, because I tried to move the images before IM even touches them and it still doesn't work.

I'm at a loss. I looked through the forums. Seems folks have problems with FileMove() but their solutions don't seem to apply here.

All ideas will be highly appreciated.

goodnight & goodluck,...

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
omikron48

All that's left after a failed manual move would be to check for file locks or look up the ACL to see if you have modify rights to the files.

Share this post


Link to post
Share on other sites
jaberwacky

All that's left after a failed manual move would be to check for file locks or look up the ACL to see if you have modify rights to the files.

OK, I just tried a manual move and they did move.

Share this post


Link to post
Share on other sites
omikron48

Maybe some code could help clarify the issue. There's definitely something else going on if a manual move succeeds but FileMove fails in a script.

Share this post


Link to post
Share on other sites
jaberwacky

my fault, here's the code that I believe is giving me problems...

::just concentrate on the setup, create panorama, cleanup regions... the rest are for in case you want to run the script... but I abstracted the code so I can't say for sure if it will replicate exactly my code but I think it would be good to go...

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Fileversion=0.0.1.105
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -d -I "D:\AutoIt\AutoIt Scripts\Includes"
#AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%"
#AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3"
#AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe"
#AutoIt3Wrapper_Run_After=md "%scriptdir%\Versions\%fileversion%"
#AutoIt3Wrapper_Run_After=copy "%in%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.au3"
#AutoIt3Wrapper_Run_After=copy "%out%" "%scriptdir%\Versions\%fileversion%\%scriptfile%%fileversion%.exe"
#AutoIt3Wrapper_Run_Tidy=y
#Tidy_Parameters=/sf
#Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#region set-up
Global Const $incTitleNum = 1; _getIncTitleNum() ; find the number by which to name the panorama.
Global Const $newDirectory = @ScriptDir & "\AutoPlog\Pictures\" & $incTitleNum
Global Const $newDirectoryTmp = $newDirectory & "\tmp"
Global Const $newNameTmp = $newDirectoryTmp & '\' & "tmp.jpg"
Global Const $newName = $newDirectory & ".jpg"
Global Const $resize = 400; _getHeightOfShortestImage()
Global Const $width = IniRead(@ScriptDir & "\Options and Settings.ini", "Options", "Width", 715)
Global Const $horzVert = "+append" ;_getHorzVert()
Global $oImg, $checkErr, $oMyError, $ret

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; this doesn't appear in the source script, just here to make this example compile
;~ Global $imageList[2] = ["<Insert image name here>.jpg", "<Insert image name here>.jpg"]
Global $imageList[2] = ["2i9mdtd.jpg", "05.07.25.taking.jpg"]
Global $directory = "<insert the directory of the images that are in $imageList with a trailing backslash>"
;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

$checkErr = DirCreate($newDirectoryTmp)
If $checkErr = 0 Then
    ConsoleWrite("Error creating $newDirectoryTmp")
    Exit (12)
Else
    FileSetAttrib($newDirectoryTmp, "-R+N")
EndIf
#endregion set-up

#region create panorama
_registerDLL()

$oImg = ObjCreate("ImageMagickObject.MagickImage.1")

$oMyError = ObjEvent($oImg, "MyErrFunc")

; shrink all images down to the height of the shortest image
For $image In $imageList
    $ret = $oImg.Convert($directory & $image, "-thumbnail", "x" & $resize, $newDirectoryTmp & '\' & $image)
    ConsoleWrite($ret)
Next

; append the shortened images into a panorama
$ret = $oImg.Convert($newDirectoryTmp & '\' & "*.jpg", $horzVert, $newNameTmp)
ConsoleWrite($ret)

; shrink the panorama to a width of 715px
$ret = $oImg.Convert($newNameTmp, "-thumbnail", $width, $newName)
ConsoleWrite($ret)

_unregisterDLL()
#endregion create panorama

#region clean-up
Switch FileExists($newName)
    Case 1 ; woo-hoo
        ConsoleWrite($newName & " exists." & @CRLF)

        ; (move|copy) the images
        Global $moveCopy = 0 ;IniRead(@ScriptDir & "\Options and Settings.ini", "Options", "Move or Copy", 1)
        Switch $moveCopy
            Case 0 ; move the originial pictures into the new dir.
                For $image In $imageList
                    ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                    ; this is the statement in question...
                    FileMove($directory & $image, $newDirectory & '\' & $image)
                    ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                Next
            Case 1 ; copy the originial pictures into the new dir. (default)
                For $image In $imageList
                    FileCopy($directory & $image, $newDirectory & '\' & $image)
                Next
        EndSwitch

        FileRecycle($newNameTmp)

        ; delete the shortened images
        $checkErr = DirRemove($newDirectoryTmp, 1)
        If $checkErr = 0 Then ConsoleWrite("There was an error deleting: " & $newDirectoryTmp)

        ; For quick and easy pasting to your image host
        Global $copyPanorama = IniRead(@ScriptDir & "\Options and Settings.ini", "Options", "Copy Panorama", 1)
        If $copyPanorama = 1 Then ClipPut($newName)

        ; opens the final directory for user convenience
        Global $openDir = IniRead(@ScriptDir & "\Options and Settings.ini", "Options", "Open Directory", 1)
        If $openDir = 1 Then ShellExecute(@ScriptDir & "\Pictures\")

        ; update 'Options and Settings.ini" to reflect the new panorama image count
        IniWrite(@ScriptDir & "\Options and Settings.ini", "Options", "Picture Title", $incTitleNum + 1)

        Exit (0)
    Case 0
        $checkErr = DirRemove($newDirectory)
        If $checkErr = 0 Then ConsoleWrite("Error removing $newDirectory: " & $newDirectory)
        Exit (9)
EndSwitch
#endregion clean-up

#region _registerDLL()
Func _registerDLL()
    $checkErr = FileInstall("C:\Program Files (x86)\ImageMagick-6.6.1-Q16\ImageMagickObject.dll", @SystemDir & "\", 1)

    Switch $checkErr
        Case 0 ; "FileInstall() did not install 'ImageMagickObject.dll'"
            Exit (11)
        Case 1
            Local $pid = Run(@ComSpec & " /c /s RegSvr32 " & @SystemDir & "\ImageMagickObject.dll", '', @SW_HIDE)
            ProcessWaitClose($pid, 300000)
;~  If Not ProcessExists($pid) Then consolewrite("Process did not exist.")
            If $pid = 0 Then ConsoleWrite("Run() timed out.")
            If @error <> 0 And @extended = 0xCCCCCCCC Then ConsoleWrite("Invalid PID.")
    EndSwitch

EndFunc ;==>_registerDLL
#endregion _registerDLL()

#region _unregisterDLL()
Func _unregisterDLL()
    $oImg = ''
    Local $pid = Run(@ComSpec & " /c /s /u RegSvr32""" & @SystemDir & "\ImageMagickObject.dll", '', @SW_HIDE)
    ProcessWaitClose($pid, 300000)
    If $pid = 0 Then ConsoleWrite("Run() timed out.")
    If @error <> 0 And @extended = 0xCCCCCCCC Then ConsoleWrite("Invalid PID.")
    FileDelete(@SystemDir & "\ImageMagickObject.dll")
EndFunc ;==>_unregisterDLL
#endregion _unregisterDLL()

#region MyErrFunc()
Func MyErrFunc()
    ConsoleWrite("AutoItCOM Test " & "We intercepted a COM Error !" & @CRLF & @CRLF & _
            "err.description is: " & @TAB & $oMyError.description & @CRLF & _
            "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _
            "err.number is: " & @TAB & Hex($oMyError.number, 8) & @CRLF & _
            "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _
            "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _
            "err.source is: " & @TAB & $oMyError.source & @CRLF & _
            "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _
            "err.helpcontext is: " & @TAB & $oMyError.helpcontext)
    Exit (10)
EndFunc ;==>MyErrFunc
#endregion MyErrFunc()
Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
MHz

I do not see where you create the folder for $newDirectory. You use no flag for FileCopy()/FileMove() which can fail if the destination folder does not already exist.

Share this post


Link to post
Share on other sites
GEOSoft

I do not see where you create the folder for $newDirectory. You use no flag for FileCopy()/FileMove() which can fail if the destination folder does not already exist.

And therein lies the reason why it works now and it didn't before. He did a manual move and it works. I'm betting that he then just deleted the files instead of the folder and then ran the script again. Because the folder was there this time it worked.

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!"

Share this post


Link to post
Share on other sites
omikron48

There we go then. I've always used the flags for FileCopy and FileMove so I've never experienced such complications. I always force create and overwrite since I never had a concern with keeping pre-existing files in the destination folder.

Share this post


Link to post
Share on other sites
GEOSoft

There we go then. I've always used the flags for FileCopy and FileMove so I've never experienced such complications. I always force create and overwrite since I never had a concern with keeping pre-existing files in the destination folder.

The important flag this time was

8 = Create destination directory structure if it doesn't exist


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!"

Share this post


Link to post
Share on other sites
jaberwacky

I do not see where you create the folder for $newDirectory. You use no flag for FileCopy()/FileMove() which can fail if the destination folder does not already exist.

Supposedly DirCreate() will create any parent paths if they aren't already created.

"Remarks

This function will also create all parent directories given in "path" if they do not already exist."

Also, using FileMove( '[from path], [to path], 8 or 8+1) does not work in my original source script.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
GEOSoft

I can see where you have DirCreate($newDirectoryTmp) but I fail to find a DirCreate($newDirectory)


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!"

Share this post


Link to post
Share on other sites
jaberwacky

I can see where you have DirCreate($newDirectoryTmp) but I fail to find a DirCreate($newDirectory)

Ok, that was it! Maybe the helpfile is wrong? Because I'm pretty sure that it says that non-existant parent paths will be created...

My script worked fine until one day it just stopped!

Thank you GeoSoft, Omikron48, and Mhz. I appreciate your help! :idea:

Nope, stopped again...

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites
jaberwacky

Seems to work right when I comment out this function:

#region set-up
Global Const $incTitleNum = _getIncTitleNum() ; find the number by which to name the panorama.
Global Const $newDirectory = @ScriptDir & "\Pictures\" & $incTitleNum
Global Const $newDirectoryTmp = $newDirectory & "\tmp"
Global Const $newNameTmp = $newDirectoryTmp & '\' & "tmp.jpg"
Global Const $newName = $newDirectory & ".jpg"
Global Const $resize = 400;_getHeightOfShortestImage()
Global Const $width = IniRead(@ScriptDir & "\Options and Settings.ini", "Options", "Width", 715)
Global Const $horzVert = _getHorzVert()
Global $oImg, $checkErr, $oMyError, $ret

...

#endregion set-up

#region _getHeightofShortestImage()
Func _getHeightofShortestImage()
    Local $array0[$imageCount]
    Local $array1[$imageCount]

    _GDIPlus_Startup()

    For $i = 0 To $imageCount - 1
        $array0[$i] = _GDIPlus_ImageLoadFromFile($directory & $imageList[$i])
        $array1[$i] = _GDIPlus_ImageGetHeight($array0[$i])
    Next

    _GDIPlus_Shutdown()

    _ArraySort($array1, 0)

    Return $array1[0]
EndFunc ;==>_getHeightofShortestImage
#endregion _getHeightofShortestImage()
Edited by jaberwocky6669

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  

×