Ok, you have to consider me a total Java novice. I knew enough to write a few applets, but that was years ago. Now I've decided to tackle a few projects in cleaning up my pc and am trying to use Java, but have found that what I do know is rusty and even if it weren't it isn't enough.
The problem I'm having is that I have tons of pics in various directories that I want to rename, or append the year 2005 to the names of them. For example, I have a folder, Pics, that contains several subfolders. One is named Holidays. In the Holidays folder is about 300 images that I would like to just add "---2005" to the end of so that "laborday014.jpg" would become "laborday014---2005.jpg". You get the idea. Having written only applets in the past I am totally lost for how to navigate and work with files on my hard drive. So here's what I know right now....
I'm going to need to import java.io.* and java.util.*. Thanks to a different thread here already I know that I can do something like this to read the filenames into an array...
File file = new File(c:\Pics\Holidays);
String[] list = file.list();
As I understood the other thread this should read all 342 or whatever pics in the Holidays folder into the array named list.
From there I believe that I can then sort the array by name using..
sort(list);
This should then sort the array into alphabetical order, which is not necessary for this folder but could be in other folders if I want to append increasing numbers to files such as "auntpolly---001.jpg", "auntpolly---002.jpg", etc. Either way I need the experience working with arrays so I'm just checking that I am using the sort() function correctly.
Ok, from there I can set up a for loop to iterate through the array and rename each file as it goes. Something like this...?
for(int 1=0; 1<list.length; i++)
{current=file.this;
String newName=current+"---2005";
renameTo(newName);}
This is where I start to seriously doubt myself. It seems like something is missing, but I've kicked through a few reference books and it's not readily apparent. My first concern is that when I am reading the file names into the array, am I also reading the extension? If so, then am I not renaming "laborday014.jpg" to "laborday014.jpg---2005"? That would not be a good thing at all. So question one is.. am I just picking up the file names or am I picking up the extensions as well? The second question has to do with the renameTo() function. What am I renaming? Will this rename the actual file or just rename the value in the array? I know this must seem like I know just enough to be dangerous, but I would appreciate any help I can get here.
The problem I'm having is that I have tons of pics in various directories that I want to rename, or append the year 2005 to the names of them. For example, I have a folder, Pics, that contains several subfolders. One is named Holidays. In the Holidays folder is about 300 images that I would like to just add "---2005" to the end of so that "laborday014.jpg" would become "laborday014---2005.jpg". You get the idea. Having written only applets in the past I am totally lost for how to navigate and work with files on my hard drive. So here's what I know right now....
I'm going to need to import java.io.* and java.util.*. Thanks to a different thread here already I know that I can do something like this to read the filenames into an array...
File file = new File(c:\Pics\Holidays);
String[] list = file.list();
As I understood the other thread this should read all 342 or whatever pics in the Holidays folder into the array named list.
From there I believe that I can then sort the array by name using..
sort(list);
This should then sort the array into alphabetical order, which is not necessary for this folder but could be in other folders if I want to append increasing numbers to files such as "auntpolly---001.jpg", "auntpolly---002.jpg", etc. Either way I need the experience working with arrays so I'm just checking that I am using the sort() function correctly.
Ok, from there I can set up a for loop to iterate through the array and rename each file as it goes. Something like this...?
for(int 1=0; 1<list.length; i++)
{current=file.this;
String newName=current+"---2005";
renameTo(newName);}
This is where I start to seriously doubt myself. It seems like something is missing, but I've kicked through a few reference books and it's not readily apparent. My first concern is that when I am reading the file names into the array, am I also reading the extension? If so, then am I not renaming "laborday014.jpg" to "laborday014.jpg---2005"? That would not be a good thing at all. So question one is.. am I just picking up the file names or am I picking up the extensions as well? The second question has to do with the renameTo() function. What am I renaming? Will this rename the actual file or just rename the value in the array? I know this must seem like I know just enough to be dangerous, but I would appreciate any help I can get here.