david1337 Posted March 24, 2015 Share Posted March 24, 2015 Hey guys How can I move ALL content from folderA to folderB? $source = 'C:\folderA' $dest = 'C:\folderB' dirmove($source, $dest, 1) ; This just moves folderA under folderB, which is not what I want! filemove --> only moves files, not directories Link to comment Share on other sites More sharing options...
javiwhite Posted March 24, 2015 Share Posted March 24, 2015 Hey David, Try this filemove($Source & "\*.*", $Dest,1) Cheers Javi give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime. Link to comment Share on other sites More sharing options...
david1337 Posted March 24, 2015 Author Share Posted March 24, 2015 (edited) Hey David, Try this filemove($Source & "\*.*", $Dest,1) Cheers Javi Hi Javi Thank you for answering! Your line just moved all files from the destination, not the folders David Edited March 24, 2015 by david1337 Link to comment Share on other sites More sharing options...
javiwhite Posted March 24, 2015 Share Posted March 24, 2015 Hey David, Ahh, sorry, i didn't realise there were subfolders. I don't believe either function will move both folders and files. This is a quick workaround though: $source = 'C:\folderA' $dest = 'C:\folderB' FileMove($source & "\*.*", $dest, 1) ;Move all source folder files first $hSearch = FileFindFirstFile($Source & "\*.*") ;Now find any remaining (in this case: folders) if $hSearch = -1 then exit ;No folders While 1 $hFilename = FileFindNextFile($hSearch) ;get next file name if @ERROR then exitloop ;No more files DirCreate($Dest & "\" & $hFilename) ;Recreate file in new location FileMove($Source & "\" & $hFilename & "\*.*", $Dest & "\" & $hFilename,1) ;move all contents to new locations, whilst creating the new folder WEnd thanks Javi give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime. Link to comment Share on other sites More sharing options...
david1337 Posted March 24, 2015 Author Share Posted March 24, 2015 Hey David, Ahh, sorry, i didn't realise there were subfolders. I don't believe either function will move both folders and files. This is a quick workaround though: $source = 'C:\folderA' $dest = 'C:\folderB' FileMove($source & "\*.*", $dest, 1) ;Move all source folder files first $hSearch = FileFindFirstFile($Source & "\*.*") ;Now find any remaining (in this case: folders) if $hSearch = -1 then exit ;No folders While 1 $hFilename = FileFindNextFile($hSearch) ;get next file name if @ERROR then exitloop ;No more files DirCreate($Dest & "\" & $hFilename) ;Recreate file in new location FileMove($Source & "\" & $hFilename & "\*.*", $Dest & "\" & $hFilename,1) ;move all contents to new locations, whilst creating the new folder WEnd thanks Javi Hi Javi Okay this time it came closer. What it did: - It moved all files from A to B - It copied all subfolders and the files within them from A to B (but the subfolder still exists in A, without the files though) - Folders + their files inside a subfolder where not copied/moved Man I didn't realize that this would be so complicated in Autoit! Link to comment Share on other sites More sharing options...
Solution javiwhite Posted March 24, 2015 Solution Share Posted March 24, 2015 It seems i might have overcomplicated the situation somewhat. Try this: $source = 'C:\folderA' $dest = 'C:\folderB' FileMove($source & "\*.*", $dest, 1) ;Move all source files first $hSearch = FileFindFirstFile($Source & "\*.*") ;Now find any remaining (in this case: folders) if $hSearch = -1 then exit ;No folders While 1 $hFilename = FileFindNextFile($hSearch) if @ERROR then exitloop ;No more files DirMove($source & "\" & $hFilename, $Dest,1);move subdir and all contents to new location WEnd Thanks Javi give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime. Link to comment Share on other sites More sharing options...
funkey Posted March 24, 2015 Share Posted March 24, 2015 What about this: Global $iSuccess = _XCopy_DirMove(@ScriptDir & "\Test", @ScriptDir & "\Test2") ConsoleWrite("Success: " & $iSuccess & @LF) Func _XCopy_DirMove($sSourcePath, $sTargetPath) Local $iErrorlevel = RunWait('xcopy "' & $sSourcePath & '" "' & $sTargetPath & '" /E /Y /R /H /K /I', "", @SW_HIDE) If $iErrorlevel = 0 Then ; Copying without error DirRemove($sSourcePath, 1) EndIf Return SetError($iErrorlevel, 0, $iErrorlevel == 0) EndFunc ;==>_XCopy_DirMove Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
david1337 Posted March 24, 2015 Author Share Posted March 24, 2015 It seems i might have overcomplicated the situation somewhat. Try this: $source = 'C:\folderA' $dest = 'C:\folderB' FileMove($source & "\*.*", $dest, 1) ;Move all source files first $hSearch = FileFindFirstFile($Source & "\*.*") ;Now find any remaining (in this case: folders) if $hSearch = -1 then exit ;No folders While 1 $hFilename = FileFindNextFile($hSearch) if @ERROR then exitloop ;No more files DirMove($source & "\" & $hFilename, $Dest,1);move subdir and all contents to new location WEnd Thanks Javi That worked! Thank you so much Javi! @ funkey I'm sure that works too. Two different ways to accomplish the same thing Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now