On Sunday 01 September 2002 14:56, rohit kuttappan wrote:
> Greeting all!
>
> I'm trying to write a Java utility that could enumerate and rename files =
> in a specified directory.
> Say, I have a directory called MyPictures which contains .jpg & .gif =
> files. I want to rename=20
> all these files such that now they are 01.jpg, 02.jpg, 03.gif etc.
>
> I know there is a File class in the IO package that will list out all =
> the files in=20
> a directory (but it does not tell how many files there are)
Why is that? I haven't a java compiler at hand but the docs about
File.list(); say: If this abstract pathname does not denote a directory, then
this method returns null. Otherwise an array of strings is returned, one for
each file or directory in the directory.
Sounds to me like you just do:
File[] fileNames = new File ("myDirectory").listFiles();
int noOfFiles = fileNames.length;
for (int i = 0; i < noOfFiles.length; i++) {
fileNames[i].renameTo("myPrefix"+i+"whatever");
}
I like the Core Java Series from Sun. I haven't read it but they also have a
book about Swing.
Patrik
> a
> renameTo( ) method which renames the file.=20
>
> Is there a way I can find out exactly how many files ther are in a =
> directory and rename
> them in the desired way. Please help me.=20
>
> Also, could you please recomment a good book on swing for beginers and / =
> intermediate leve. Thanks in advance
>
> Rohit
>
>
> To change your JDJList options, please visit:
> http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm