Jump to content

[Solved] Awkward FileMove() problem.


MvGulik
 Share

Recommended Posts

I'm trying to move a file with FileMove()

When I try it at the startup of the script, or with a small test script, the file gets moved.

But when I try the same thing later on in the program, the filemove fails.

:)

Anyone any idea's where, or for what I should look for.

---

some partial code, just in case.

At the bottom of the script part are the test function calls I tried.

;test1() ;; ok
;test2() ;; ok
MAIN()
;test1() ;; fails !!!
;test2() ;; ok ???

Func test1($sSource = '', $sTarget = '')
    DebugOut('>test()', @WorkingDir) ;### Debug DebugOut
    DebugOut('-$sSource', $sSource) ;### Debug DebugOut
    DebugOut('-$sTarget', $sTarget) ;### Debug DebugOut
    Local $try = 2
    If Not $sSource Then
        $try = 3
        $sSource = 'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\File_001.tmp'
        $sTarget = 'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\GMM_data\GMM_backup\File_001.tmp'
    EndIf
    If Not FileMove($sSource, $sTarget, 9) Then
        DebugOut('![' & $try & ']FileMove failed on "' & $sSource & ', ' & $sTarget & '"', @ScriptLineNumber, $AU3FILE[1])
    Else
        DebugOut('+[' & $try & ']') ;### Debug DebugOut
    EndIf
EndFunc
Func test2()
    ConsoleWrite('>test2()' & @CRLF)
    Local $BSL = '\'
    Local $file = 'file.tmp'
    Local $dir1 = 'dir1.tmp'
    Local $dir2 = 'dir2.tmp'

    Local $source = @ScriptDir & $BSL & $dir1 & $BSL & $file
    Local $target = @ScriptDir & $BSL & $dir2 & $BSL & $file

    ConsoleWrite('$source = ' & $source & @CRLF)
    ConsoleWrite('$target = ' & $target & @CRLF)

    If Not FileExists($dir1) Then DirCreate($dir1)
    If @error Then ConsoleWrite('!DirCreate,1' & @CRLF)

    If Not FileExists($dir2) Then DirCreate($dir2)
    If @error Then ConsoleWrite('!DirCreate,2' & @CRLF)

    If Not FileExists($source) Then FileWrite($source, 'txt')
    If @error Then ConsoleWrite('!FileWrite' & @CRLF)

    If FileExists($target) Then FileDelete($target)
    If @error Then ConsoleWrite('!FileDelete' & @CRLF)

    If Not FileMove($source, $target) Then
        ConsoleWrite('!FileMove' & @CRLF)
    Else
        ConsoleWrite('+FileMove' & @CRLF)
    EndIf

EndFunc

;test1() ;; ok
;test2() ;; ok
MAIN()
;test1() ;; fails !!!
;test2() ;; ok ???
Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

When working with files, I always use while loop to check if FileMove is successful. Something like

this:

$move = FileMove("C:\x", C:\y")

While 1
    If $move = 1 Then ExitLoop
    If $move = 0 Then MsgBox(0,"","Failed")
WEnd

Moving files can take some times, check if file successfully moved right after you

called FileMove function sometimes return other than 1(sucess) value...

I don't know if this is relevant to your question.. hehehe :)

Hi ;)

Link to comment
Share on other sites

I don't know if this is relevant to your question.. hehehe ;)

Not really, no. :)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

I would guess that "'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\File_001.tmp'" is there for first time test1 is run, but not the second time. It moves, not copies the file, this "'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\File_001.tmp'" is a invalid path after test1 has run once.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Are you running test1() twice in the script? If yes, as Bo8ster said, it won't work, since the file has already been moved once. So next time it won't be found. Also, to debug why the file hasn't been moved, why don't you check what value is returned by the FileMove() function?

From Help File:

Failure: Returns 0 if source cannot be moved or if dest already exists and flag=0.
[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com
Link to comment
Share on other sites

I would guess that "'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\File_001.tmp'" is there for first time test1 is run, but not the second time. It moves, not copies the file, this "'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\File_001.tmp'" is a invalid path after test1 has run once.

LOL, nope :)

Same results with the one I'm using to track it down ...

Global $iTest0count = 0
Func test0($iLine,$sFile,$err=@error,$ext=@extended)
    Global $iTest0count
    Local $sSource, $sTarget
    Local $sFile1 = 'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\File_999.tmp'
    Local $sFile2 = 'C:\CODE\_WORK_\Dev_AutoIt\FileSwapper\Test_Setup\GMM_data\GMM_backup\File_999.tmp'
    $iTest0count += 1
    if FileExists($sFile1) Then
        $sSource = $sFile1
        $sTarget = $sFile2
    Else
        $sSource = $sFile2
        $sTarget = $sFile1
    EndIf
    If Not FileMove($sSource, $sTarget) Then
        DebugOut($sFile&'('&$iLine&',) test0 | '&$iTest0count&' | !!! ')
        Return SetError($err,$ext,1)
    Else
        FileMove($sTarget, $sSource)
        DebugOut($sFile&'('&$iLine&',) test0 | '&$iTest0count&' | --- ')
        Return SetError($err,$ext,0)
    EndIf
EndFunc

... allmost there ... seem related to some crc32 code I picked up on the way.

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

:)

crc32file example that I blindly copied and past into my code ... never closed the file it opened.

MD5,SHA1,CRC32,RC4,BASE64,XXTEA

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

It is difficult to help with what you are posting IMO :)

You have shown us code which produces output but not shown us what the output is.

You move a file, as bo8ster says, then wonder why you can't move it again.

You have a function main which is called before the function test1 which fails but you don't tell us what happens in main which could be relevant.

You show us a test which uses a completely different file name and different parameters (very strange parameters) and which has no obvious way of helping to debug test1.

If you add some extra debugging code in test1 you can probably find the answer more quickly than using the forum.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Mmm, ok I'm very unclear. :)

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

Mmm, ok I'm very unclear. :)

1.) Post All of your code.

2.) Post All of the output from Scite. I assume DebugOut ends up as a ConsoleWrite().

3.) Check the return value of FileMove and then output or post the result.

4.) Know the exact status of the files on the file system as the program runs.

If its solved now - don't worry.

Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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