I have a file Structure C:\Files\java. In java I have 3 folders F1, F2, F3 and some files . In each of the folders there are zip files a.zip, b.zip, c.zip. I have to go into each folder and move the file to different place. Ex:C:\Moved.
Initial file Structure C:\Files\java\F1\a.zip, C:\Files\java\F2\b.zip,C:\Files\java\F3\c.zip
After moving: C:\Moved\a.zip, C:\Moved\b.zip, C:\Moved\c.zip
how do I achieve this?
Thanks in Advance.
Take a look at the java.io.File.renameTo() documentation.
Sree Potluri wrote:What do you mean by "And the difference is?" I am not understanding your question. I want to move files from one directory, where in if the path is the directory then go into the directory until there are no more directories, then take the file and put it in another location.
Sree Potluri wrote: I want to know how many files are there in F1 directory. If there are F11, F12.. inside F1, then it should go to each individual directory and move the file to C:\Moved folder
So, in this particular example you want to "rename" the original file from C:\Files\java\F1\a.zip to C:\Moved\a.zip. That isn't what you coded. Instead you tried to rename the original file from C:\Files\Java\F1\a.zip to C:\Moved, which is going to fail if that directory already exists.
Sree Potluri wrote:What do you mean by "And the difference is?" I am not understanding your question.
I mean that conceptually, renaming a file and moving a file are the same thing. In each case you're changing the absolute path of the file. Compare Unix commands - whether you want to move or rename a file you still use the mv command.