I’m working on a small application in Java that takes a directory structure and renames the files according to a certain format, after parsing the original name.
What is the best Java class / methodology to use in order to facilitate these file operations?
Edit: the question is only regarding the file operations part, I got the “getting the formatted name” down 🙂
Edit 2: Also, how do I list files recursively?
Use
java.io.FileListing all files in a directory
http://www.javaprogrammingforums.com/java-code-snippets-tutorials/3-how-list-all-files-directory.html
UPDATE
To list the files recursively, your best approach is fairly easy:
isDirectory()method), add it to the back of the queue.Else, process this next file as needed (e.g. print)
An example (I think a bit different from my approach above) is http://www.javapractices.com/topic/TopicAction.do?Id=68
Renaming a file
http://www.roseindia.net/java/example/java/io/RenameFileOrDir.shtml
Finding a new name to rename to
I’m not sure what you want the formatting rules to be – when I implemented the same utility in Perl for my own use I used Regular Expressions. For Java, that’d be java.util.regex