Jump to content
Sign in to follow this  
david1337

Move all content from folderA to folderB

Recommended Posts

david1337

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

Share this post


Link to post
Share on other sites
javiwhite

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.

Share this post


Link to post
Share on other sites
david1337

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 by david1337

Share this post


Link to post
Share on other sites
javiwhite

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.

Share this post


Link to post
Share on other sites
david1337

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! :)

Share this post


Link to post
Share on other sites
javiwhite

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.

Share this post


Link to post
Share on other sites
funkey

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 to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post


Link to post
Share on other sites
david1337

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 :)

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  

×