MPAA | Credit Cards | Free Advertising | Buy PSP | Car Credit
Renaming files in JAVA? [Archive] - PCMech Forums

PDA

View Full Version : Renaming files in JAVA?


achilipepper
05-27-2004, 12:00 PM
ok so here i am at work, openning folder after folder, renaming file after file....
i have a good knowledge of JAVA (degree in computer science), but i dont know how to do the following:
1. with a given directory, get an array of the folders in it
2. open one of the folders, get an array of the files inside, rename each file
basically i need to rename each file to the name of the folder they reside in with a -1, -2, -3, -4, -5, etc appended to the end, then repeat for the next folder of files. seems easy enough, i just dont know the above steps.

help!

aym
05-27-2004, 07:28 PM
Check out the File class:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html


It has methods for enumerating directory contents (listFiles), and renaming files (renameTo).

If you need more help on those methods, just post ;)