Jump to content

Moving all files AND directories


nitro322
 Share

Recommended Posts

I'm sure this is a dumb question, but I haven't been able to find any easy answer. Let's say I have two directories on my system named C:\test1\ and C:\test2\. Now, I'd like to move the contents of test1 to test2. How exactly am I supposed to do that?

The most logical answer seems to be the filemove() and/or dirmove() functions, but neither do what I want. For example:

$source = 'C:\test1'
$dest = 'C:\test2'

; does nothing
dirmove($source, $dest, 0)

; moves test1 under test2
dirmove($source, $dest, 1)

; only moves files, not directories
filemove($source, $dest, 0)
filemove($source, $dest, 1)
filemove($source & '\*', $dest, 0)
filemove($source & '\*', $dest, 1)

; does nothing
dirmove($source & '\*', $dest, 0)
dirmove($source & '\*', $dest, 1)

dirmove($source, $dest, 1) comes the closest, but I just want the contents of the directory moved, not the directory itself.

The way I've handled this in the past is to do a filemove() to move all files, then a filefindnextfile() while loop to get the name of each subdirectory and run individual dirmove()'s on those subdirectories. It works fine, but just seems terribly complicated for such a seemingly simple task.

Any thoughts on this?

Edited by nitro322
Link to comment
Share on other sites

You want everything in the directory moved, but not the directory itself? Ok:

$source = 'C:\test1'
$dest = 'C:\test2'

Dirmove($source, $dest, 1)
DirCreate($source)

I believe that is what you want if i understood correctly?

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Link to comment
Share on other sites

Did you try FileFind* and use wild cards to find all files (*.*), and then FileMove in a For loop? That way you never actually tamper with the directory folder. (That's probably what DirMove does in part, I haven't looked at the source)

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
Link to comment
Share on other sites

From the helpfile:

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

Dammit, i didn't see that. That is terrible. I can't believe that it would do that. There should be a third option to allow it to simply overwrite the directory.

In the mean time, you can just do it this way i would assume:

$source = 'C:\test1'
$dest = 'C:\test2'
If DirCopy($source,$dest,1) Then DirRemove($source,1)
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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