ALIENQuake

DirMove - how to fix "destination already exists" > folder moved inside the destination?

22 posts in this topic

Hi,

from the DirMove page we have:

Quote

If the source and destination are on different volumes or UNC paths are used then a copy/delete operation will be performed rather than a move.

If the destination already exists and the overwrite flag is specified then the source directory will be moved inside the destination.

I'm facing exactly the same issue and I need a simplest way to fix it. Could somebody take look at this code:

Func _Extract_MoveMod($p_Dir)
    Local $Success=0
    $Files=_FileSearch($g_GameDir & '\' & $p_Dir, '*')
    For $f=1 to $Files[0]
        If StringInStr(FileGetAttrib($g_GameDir & '\' & $p_Dir & '\' & $Files[$f]), "D") Then
            $Success = DirMove($g_GameDir & '\' & $p_Dir & '\' & $Files[$f], $g_GameDir, 1)
        Else
            $Success = FileMove($g_GameDir & '\' & $p_Dir & '\' & $Files[$f], $g_GameDir & '\', 1)
        EndIf
        If $Success = 0 Then Return 0
    Next
    $Success = DirRemove($g_GameDir & '\' & $p_Dir, 1)
    Return $Success
EndFunc   ;==>_Extract_MoveMod

and tell me how I can fix this inside that function?

P.S. Why DirMove act such way is beyond my reason, especially as default and there is no flag to change it.

Share this post


Link to post
Share on other sites



The example suggest DirMove with all inside sourcedir, Filemove and DirRemove in your func must throw errors because path doesn't exist (it's already moved).

Just try example and you will know how to short your function and also geting a runable function.

 

Share this post


Link to post
Share on other sites

You reply is not helpful, is there any replacement for DirMove function which won't have such drawback? 

Share this post


Link to post
Share on other sites

I want an replacement for DirMove function which won't act as it's described in remarks: If the destination already exists and the overwrite flag is specified then the source directory will be moved inside the destination.

It's absoluty devastating for my script logic. It act differently from everything I've used so far.

Share this post


Link to post
Share on other sites

When I've move directory and the designation location already has the same directory and the overwrite flag is enables, I've expect that all files would be overwritten. That's what I need because i'm replacing old files with new version of files by moving them from subfolder.

Share this post


Link to post
Share on other sites

So....

Func _DirMove($Source, $Destination, $Flag)
    ;; Pseudo code
    If Destination exists And flag is Set Then
        Remove destination Dir
        Move source dir 
        Return
    EndIf
    Move source dir
EndFunc

 


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I cannot remove whole Destination folder because there are files which aren't present inside source folder so I've on;y updating files which were actually changed.

Share this post


Link to post
Share on other sites

The " source directory will be moved inside the destination." so instead of having:

Source: D:\A\*
Dest: E:\A\*

i endup with E:\A\A\*

 

Share this post


Link to post
Share on other sites

I've tested it and this behavior is the reason of this thread. 

Share this post


Link to post
Share on other sites
#include <File.au3>

;Global $g_GameDir = @ScriptDir & "\GameDir"
;Global $p_Dir = "TestDir"

;ConsoleWrite(_Extract_MoveMod($p_Dir) & @CRLF)

Func _Extract_MoveMod($p_Dir)
    Local $Success = 0, $Error = 0
    Local $Files = _FileListToArrayRec($g_GameDir & '\' & $p_Dir, '*', 0, 1, 1, 1)
    For $f = 1 To UBound($Files) - 1
        ConsoleWrite($Files[$f] & @CRLF)
        If StringInStr(FileGetAttrib($g_GameDir & '\' & $p_Dir & '\' & $Files[$f]), "D") Then
            $Success = DirCopy($g_GameDir & '\' & $p_Dir & '\' & $Files[$f], $g_GameDir & '\' & $Files[$f], 1)
        Else
            $Success = FileCopy($g_GameDir & '\' & $p_Dir & '\' & $Files[$f], $g_GameDir & '\' & $Files[$f], 1)
        EndIf
        If $Success = 0 Then $Error += 1
    Next
    If ($Error == 0) Then Return (DirRemove($g_GameDir & '\' & $p_Dir, 1) <> 0)
    Return SetError(1, $Error, 0)
EndFunc   ;==>_Extract_MoveMod

 

1 person likes this

“The world won’t care about your self-esteem. The world will expect you to accomplish something Before you feel good about yourself.”

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

 

 

Edited by MaxPlankpar

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Have tried it with this syntax and does the same happen?:

DirMove("D:\A","E:",1)

Jos

Ps to others: Could you guys simply stop for a moment with all the alternatives and none related posts so we can stick with the reported issue? ;)

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Ok, I've almost got it to work:

1. Included new function code
2. Got errors about missing functions > add every required/missing file, finally new function is executed
3. Got another error regarding array.au3:

Func _ArrayAdd(ByRef $aArray, $vValue, $iStart = 0, $sDelim_Item = "|", $sDelim_Row = @CRLF, $iForce = $ARRAYFILL_FORCE_DEFAULT)

    If $iStart = Default Then $iStart = 0
    If $sDelim_Item = Default Then $sDelim_Item = "|"
    If $sDelim_Row = Default Then $sDelim_Row = @CRLF
    If $iForce = Default Then $iForce = $ARRAYFILL_FORCE_DEFAULT
    If Not IsArray($aArray) Then Return SetError(1, 0, -1)
    Local $iDim_1 = UBound($aArray, $UBOUND_ROWS)
    Local $hDataType = 0
    Switch $iForce
        Case $ARRAYFILL_FORCE_INT
            $hDataType = Int
        Case $ARRAYFILL_FORCE_NUMBER
            $hDataType = Number
        Case $ARRAYFILL_FORCE_PTR
            $hDataType = Ptr
        Case $ARRAYFILL_FORCE_HWND
            $hDataType = Hwnd
        Case $ARRAYFILL_FORCE_STRING
            $hDataType = String
    EndSwitch

Line 84:

Quote

---------------------------
AutoIt Error
---------------------------
Line 84  (File "D:\EET-BWS\BWS\BiG World Setup\Includes\Array.au3"):

$hDataType = Int
$hDataType = Int^ ERROR

Error: Missing separator character after keyword.
---------------------------
OK   
---------------------------
 

and the reason is - I've using old AutoIt.exe 3.2.12.1 Please don't kill me when I say that I cannot update au3 version.  It would require rewriting 900KB of the code. Is there any way of fixing such bug without need to update AutoIt?
 

Share this post


Link to post
Share on other sites
1 hour ago, ALIENQuake said:

and the reason is - I've using old AutoIt.exe 3.2.12.1 Please don't kill me when I say that I cannot update au3 version.

I think you used wrong path in dest, also i think you never tested (with installed 3.3.10.0 or above) the example DirMove in helpfile.

The actual error is caused using no Parameters for func int, it maybe caused by corrupting (wrong editing) of your array.au3.

I'm working with AutoIt since February 2008 your used version was already outdated at that time. Not updating to actaul stable is like Robison Crusoe living on a island.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

I've not edited Array.au3 but I've taken it from newest AutoIt version. I think that the best is to avoid using "_FileListToArrayRec" function in Trong example. Then I wouldn't need Array.au3

Or ... I can just take this part of the code from Trong:

$Success = DirCopy($g_GameDir & '\' & $p_Dir & '\' & $Files[$f], $g_GameDir & '\' & $Files[$f], 1)

and replace the corresponding line in my code. Initial testing shows it works as expected. So adding "& '\' & $Files[$f]" to DirMove seems fixed it. I will do some more testing but already want to thanks everyone involving.

Edited by ALIENQuake

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

  • Similar Content

    • Wicked_Caty
      By Wicked_Caty
      I want to move the content of D:\downloads to D:\pictures in my program. I found DirMove, but that causes problems...
      Func Move($dest) DirMove("D:\downloads\", "D:\pictures\ABC\" & $dest) DirCreate("D:\downloads") EndFunc In a prior program exactly this piece of code did the job always properly, but now not anymore. The source path stays untouched, and a destination folder is created but empty.
      I don't have a clue why it doesn't work anymore now. I've checked it dozens of times, read the article about DirMove, tried it with dozens of different combinations, but none lead to the result. I want the content of D:\downloads in D:\pictures\ABC without having another downloads folder within the destination folder or anything else... Thanks!
      D:\downloads\cute_kitten.jpg should be D:\pictures\ABC\cute_kitten.jpg afterwards.
    • megaservo
      By megaservo
      Hi All, 
      I'm making a stage 1 preparation script to apply to target worksation Win 7 and Win 8.1 machines -in preparation to running a separate batch script later (stage 2) within our Windows Server with "netdom.exe move" xxxxxxxx
      Stage 1 Script Tasks: 
      1. delete some common shortcuts
      2. Then move all files within common user profile backup locations - including any files in the sub-directories of the common backups locations within each users profile folder. 
      Stage 1 Script Purpose: 
      Make it easy for staff to grab files and folders from one C:\_Backup directory
      Stage 1 Script PROBLEM:
      The script successfully removes the desired shortcuts - that part works well.
      Problem is it only copies files in root directory of each users common folder (eg: Desktop) but doesn't move all the sub-directories and its files and move it to the corresponding backup directory. I've searched the whole AutoIT forum domain for ideas but I've hit a dead end. 
       
      Here is the code: 
      ;START TASKS-------------------------------------------------------------------------- #include <FileConstants.au3> $ccsystem32 = @SystemDir ;define C:\Windows\System32 folder $ccdesktop = @DesktopCommonDir ;define all users desktop location ;rename CompanyName Remote Desktop shortcut FileCopy($ccdesktop&"\Remote Desktop.rdp", $ccdesktop&"\Company Remote Desktop.rdp", 0) ;delete copies of "SHIP", "eKeySilent", "eKey Manual Login", "eKey Admin" and "ConnX Login" from every profile, adds a copy ot each Desktop folder. $folder = StringLeft(@UserProfileDir,StringInStr(@UserProfileDir,"\",0,-1)) $search = FileFindFirstFile($folder&"*") While 1 $profile = FileFindNextFile($search) If @error Then ExitLoop If FileExists($folder&$profile&"\desktop\SHIP.url") Then FileDelete($folder&$profile&"\desktop\SHIP.url") EndIf If FileExists($folder&$profile&"\desktop\ekeySilent.lnk") Then FileDelete($folder&$profile&"\desktop\ekeySilent.lnk") EndIf If FileExists($folder&$profile&"\desktop\eKey Manual Login.url") Then FileDelete($folder&$profile&"\desktop\eKey Manual Login.url") EndIf If FileExists($folder&$profile&"\desktop\ConnX Login.lnk") Then FileDelete($folder&$profile&"\desktop\ConnX Login.lnk") EndIf If FileExists($folder&$profile&"\desktop\eKey Admin.url") Then FileDelete($folder&$profile&"\desktop\eKey Admin.url") EndIf If FileExists($folder&$profile&"\desktop\Remote Desktop.rdp") Then FileDelete($folder&$profile&"\desktop\Remote Desktop.rdp") EndIf ;backup desktop folder of each user If FileExists($folder&$profile&"\desktop\"&"*.*") Then FileMove($folder&$profile&"\desktop\"&"*.*", "C:\_Backup\"&$profile&"\Desktop\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup downloads folder of each user If FileExists($folder&$profile&"\downloads\"&"*.*") Then FileMove($folder&$profile&"\downloads\"&"*.*", "C:\_Backup\"&$profile&"\Downloads\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup Documents folder of each user If FileExists($folder&$profile&"\documents\"&"*.*") Then FileMove($folder&$profile&"\documents\"&"*.*", "C:\_Backup\"&$profile&"\Documents\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup pictures folder of each user If FileExists($folder&$profile&"\pictures\"&"*.*") Then FileMove($folder&$profile&"\pictures\"&"*.*", "C:\_Backup\"&$profile&"\Pictures\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup music folder of each user If FileExists($folder&$profile&"\music\"&"*.*") Then FileMove($folder&$profile&"\music\"&"*.*", "C:\_Backup\"&$profile&"\Music\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup videos folder of each user If FileExists($folder&$profile&"\videos\"&"*.*") Then FileMove($folder&$profile&"\videos\"&"*.*", "C:\_Backup\"&$profile&"\Videos\", 9) ;flag combining overwrite existing files & create destination structure EndIf ;backup IEfavorites folder of each user If FileExists($folder&$profile&"\favorites\"&"*.*") Then FileMove($folder&$profile&"\favorites\"&"*.*", "C:\_Backup\"&$profile&"\IEFavorites\", 9) ;flag combining overwrite existing files & create destination structure EndIf WEnd FileClose($search) ;end of deletion of old shortcuts and copying of user files in backup directories. I tried DirMove but I can confirm that windows wont let me move the whole eg: Desktop folder as its read only and I obviously dont want to screw up that account as well (in case we need to log into it) - so I don't want to for example delete the actual Desktop directory. Just move  
      I dont know how to move only all the sub-directories of all the above folders eg: Desktop - and not move the directory eg: Desktop itself. is it 2 problems?
      sub-directories are read only? DirMove is not allowed to copy any sub-directories?  Reason why I was asked to use FileMove and DirMove is that we are concerned of running out of C drive space if we use FileCopy and DirCopy (works on eg: Desktop dir)
      How file structure of C:\_Backup should look like on each target workstation system:
      but it should not move the for eg: C:\Users\Admin\Desktop but should move all of its files and folders. Why move not copy? C drive space is limited on each workstation, so I don't want to create double the files.  Example of Desired File structure of backup directory: C:\_Backup\ C:\_Backup\Admin\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Administrator\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Administrator.DomainName\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Default\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Default User\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\User1 .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) C:\_Backup\Public\ .\Desktop\* (includes all files & subdirectories) .\Documents\* (includes all files & subdirectories) .\Downloads\* (includes all files & subdirectories) .\IEFavorites\* (includes all files & subdirectories) .\Music\* (includes all files & subdirectories) .\Pictures\* (includes all files & subdirectories) .\Vidoes\* (includes all files & subdirectories) Anybody has any ideas or assistance? 
      Might be a really simple thing that I missed. 
      Something missing to the while loop? Maybe the whole while loop needs to be redesigned? ???
       
    • OliverA
      By OliverA
      Where is the error?

      ; DIRMOVE? $sDestination = "C:\Destination" $sName = "Folder" $sSource = @DesktopDir & "\" & $sName DirCreate($sDestination) DirCreate($sSource) Sleep(2000) ; Just for test DirMove($sSource, $sDestination) If @error = 0 Then ConsoleWrite("ERROR")
      I see both folder, but $sSource don't move to $sDestination...
      DirMove return 0
    • TanerJames
      By TanerJames
      hi,

      i don't understand DirMove function, what is problem?


      example:
      scriptDir\dictionaries

      scriptDir\Sound
      |- dictionaries

      code:
      DirMove(@ScriptDir & '\sound\dictionaries',@ScriptDir & "\dictionaries" ,1)


      result:
      scriptDir\dictionaries
      |- dictionaries

      scriptDir\Sound

      i want to sound\dictionaries folder move to dictionaries
      but it is moving under (dictionaries\dictionaries)

      thanks