Jump to content

DirMove() ... Don't like


MvGulik
 Share

Recommended Posts

I really really don't like something! about DirMove ...

(But lacking a clear question, or other words to elaborate the 'something'. Dropping this in Example section.)

(3.3.8.1)

#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -q
;~ #AutoIt3Wrapper_run_debug_mode=y
;~ Opt('MustDeclareVars', 1)
;; (3.3.8.1)

HotKeySet("{esc}", "HotKey_Esc")
HotKeySet("{F5}", "HotKey_Esc")

;; -- Start --
MAIN()
If @error Then Exit @error
Exit

;; -- Functions --

;; -- main --
Func main()
    DebugOut('>> main()') ;### Debug DebugOut.

    FileChangeDir(@ScriptDir) ;; default, just making sure.

    _cleanup()
    _setup()
    _dirmove(42)

    DebugOut('<< main()') ;### Debug DebugOut.
;~  Return 0
EndFunc

Func _cleanup()
    DebugOut('>> _cleanup()') ;### Debug DebugOut.

    _exe("DirRemove('1', 1)")
    _exe("DirRemove('9', 1)")

    ;; making sure.
    Sleep(250)
    If FileExists(1) Then DebugOut_Exit('FileExists(1) ???')
    If FileExists(9) Then DebugOut_Exit('FileExists(9) ???')

    DebugOut('<< _cleanup()') ;### Debug DebugOut.
;~  Return 0
EndFunc
Func _setup()
    DebugOut('>> _setup()') ;### Debug DebugOut.
    #cs
        O (source)
        |--- 1
        |       |--- 11
        |       |        |--- 110.file
        |       |        |--- 000.file
        |       |--- 12
        |       |        |--- 120.file
        |       |        |--- 000.file
    #ce

    _exe("DirCreate('111')")
    _exe("DirCreate('112')")
    ;
    _exe("FileWrite('111110.file', '110.file')")
    _exe("FileWrite('112120.file', '120.file')")
    ;
    _exe("FileWrite('111000.file', '000.file(11)')")
    _exe("FileWrite('112000.file', '000.file(12)')")

    ;; little delay (getting rid of some unkown random hickup at some point)
    Sleep(250)
    ;; additional check to make sure of initial setup.
    If Not FileExists('1') Then DebugOut_Exit('Not FileExists(1) ???')
    ;
    If Not FileExists('111') Then DebugOut_Exit('Not FileExists(1/11) ???')
    If Not FileExists('112') Then DebugOut_Exit('Not FileExists(1/12) ???')
    ;
    If Not FileExists('111110.file') Then DebugOut_Exit("Not FileExists(1/11/110.file') ???")
    If Not FileExists('112120.file') Then DebugOut_Exit("Not FileExists(1/12/120.file') ???")
    ;
    If Not FileExists('111000.file') Then DebugOut_Exit("Not FileExists(1/11/000.file') ???")
    If Not FileExists('112000.file') Then DebugOut_Exit("Not FileExists(1/12/000.file') ???")

    DebugOut('<< _setup()') ;### Debug DebugOut.
;~  Return 0
EndFunc
Func _dirmove($iCase = 0)
    DebugOut('>> _dirmove()') ;### Debug DebugOut.

    DebugOut('+ $iCase', $iCase) ;### Debug DebugOut.
    Switch $iCase
        Case 11
            _exe("DirMove('111', '190', 0)")
            _exe("DirMove('112', '190', 0)")
            #cs
                O (result)
                |--- 1
                |       |--- 12 (not renamed or moved)
                |       |        |--- 120.file
                |       |        |--- 000.file
                |       |--- 90 (11, renamed)
                |       |        |--- 110.file
                |       |        |--- 000.file
            #ce

        Case 12
            _exe("DirMove('111', '190', 1)")
            _exe("DirMove('112', '190', 1)")
            #cs
                O (result)
                |--- 1
                |      |--- 90 (11, renamed, no move)
                |      .       |--- 110.file
                |      .       |--- 000.file
                |      .       |--- 12 (moved, no renamed)
                |      .       .      |--- 120.file
                |      .       .      |--- 000.file
            #ce

        Case 21
            _exe("DirMove('111', '911', 0)")
            _exe("DirMove('112', '912', 0)")
            ;; result: no change.

        Case 22
            _exe("DirMove('111', '911', 1)")
            _exe("DirMove('112', '912', 1)")
            ;; result: no change.

        Case 31
            _exe("DirCreate('9')")
            Sleep(250)
            _exe("DirMove('111', '911', 0)")
            _exe("DirMove('112', '912', 0)")
            #cs
                O (result)
                |--- 1 (empty)
                |
                |--- 9
                |      |--- 11 (moved)
                |      |       |--- 110.file
                |      |       |--- 000.file
                |      |
                |      |--- 12 (moved)
                |      .      |--- 120.file
                |      .      |--- 000.file
            #ce

        Case 32
            _exe("DirCreate('9')")
            Sleep(250)
            _exe("DirMove('111', '911', 1)")
            _exe("DirMove('112', '912', 1)")
            ;; result: identical to case 31

        Case 41
            _exe("DirCreate('9')")
            Sleep(250)
            _exe("DirMove('111', '990', 0)")
            _exe("DirMove('112', '990', 0)")
            ;; second move failed ... ??? but there seems no reason for it to fail (in this case). As "by default" the folder would have ended up as additional folder in the target folder anyway.
            #cs
                O (result)
                |--- 1
                |      |--- 12 (not renamed or moved)
                |      .      |--- 120.file
                |      .      |--- 000.file
                |
                |--- 9
                |      |--- 11 (moved)
                |      |       |--- 110.file
                |      |       |--- 000.file
                |      |
            #ce

        Case 42
            _exe("DirCreate('9')")
            Sleep(250)
            _exe("DirMove('111', '990', 1)")
            _exe("DirMove('112', '990', 1)")
            #cs
                O (result)
                |--- 1
                |      |--- 9
                |      .      |--- 90 (11, moved and renamed)
                |      .      .       |--- 110.file
                |      .      .       |--- 000.file
                |      .      .       |
                |      .      .       |--- 12 (moved, no renamed)
                |      .      .       .      |--- 120.file
                |      .      .       .      |--- 000.file
            #ce
            
        Case Else
            DebugOut_Exit('_dirmove() called with unkown case value.')

    EndSwitch

    DebugOut('<< _dirmove()') ;### Debug DebugOut.
;~  Return 0
EndFunc

;; --- general debug functions ---
Func HotKey_Esc()
    Exit
EndFunc
Func _exe($sCode, $iLine = @ScriptLineNumber)
    If @NumParams > 1 Then DebugOut_Exit('_exe() called with wrong number of parameters.')
    DebugOut($sCode, Execute($sCode), $iLine)
    Return SetError(@error, @extended, 0)
EndFunc
Func DebugOut_Exit($sMsg, $vData = 'fOObAR', $iLine = @ScriptLineNumber, $iErr = @error, $iExt = @extended)
    If Not (StringRight($sMsg, 1) = '!') Then $sMsg = '! ' & $sMsg
    DebugOut($sMsg, $vData, $iLine, $iErr, $iExt)
    Exit
EndFunc
Func DebugOut($sMsg, $vData = 'fOObAR', $iLine = @ScriptLineNumber, $iErr = @error, $iExt = @extended)
    Local $sOut = $sMsg
    If Not ($vData == 'fOObAR') Then
        If IsString($vData) Then $vData = '"' & $vData & '"'
        $sOut &= ' = ' & $vData
        If 0 Then
            $sOut &= ' ... '
            $sOut &= '<' & VarGetType($vData) & '>'
            $sOut &= '[' & $iErr & ',' & $iExt & ']'
            If $iLine > 0 Then $sOut &= '{' & $iLine & '}'
        EndIf
    EndIf
    ConsoleWrite($sOut & @CRLF)
    Return SetError($iErr, $iExt, 0)
EndFunc

(+ au3 version used)

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

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