ldanet
asked on
How to move the directory ?
How to move an directory in an other directory? For example: ../Temp/Test in ../Util/Test
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Basically you create a file object representing the source directory you want to move and then another file object that would represent the directory after moving. Then you rename the first file to the second file. This moves the directiry and all its sub-directories and files.
BTW, this seems a bit unreliable.
If I use it to "move" a directory on the same drive it works :
e.g : java MoveDir c:\temp\test c:\tmp\test
However, if I try :
java MoveDir c:\temp\test d:\temp\test
it doesn't seem to work, but I get no error.
If I use it to "move" a directory on the same drive it works :
e.g : java MoveDir c:\temp\test c:\tmp\test
However, if I try :
java MoveDir c:\temp\test d:\temp\test
it doesn't seem to work, but I get no error.
Move commands will work only for local drives (local hard disks)... It will not work for mapped drive, floppy drives... If you execute the dos command you will get some error message. In java also you will get the message if map process OutputStream and errorStream.
...dviji
...dviji
I move within a partition is simply a change to the file lut for the filesystem. While a move between partition involves a copy & delete.
This is why moves often don't work across partitions/drives.
This is why moves often don't work across partitions/drives.
ASKER
Thank you for your answer!
Runtime.execute("move " + source + " " + dest);
or, do a recursive search of the source, and then open, aech file, and write it to the destination directory.
The first is obviosuly not platform indipendant, but is the easiest method, the second is a pure java implemention, but you get to wrestle with recursion and the wonderfull bugs taht all to often creep in.
GR.