Two Laptop Bag
The moose likes Java in General and the fly likes A project someone gave me...Renaming files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "A project someone gave me...Renaming files" Watch "A project someone gave me...Renaming files" New topic

A project someone gave me...Renaming files

Paul Ze

Joined: Mar 14, 2002
Posts: 18
I recently passed the Java 2 Certification in March. But I still haven't done any real programming in it except for practice. But i was talking with a friend online. She has 3,000 jpg files on her computer that she wants to rename in numerical order eg. picture1 picture 2 etc etc.
Is there an API in java that would do that? What would be the best way to go about creating a java application to do that?
My first thought would be to import all these files into a collection then use a for loop to rename each in a numeric order like picture 1 picture 2.
Any ideas out there?
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at :
Paul Ze

Joined: Mar 14, 2002
Posts: 18
Thanks that seems simple enough. The plan is for me to email the application to the user over the internet, aol to be exact. Presuming they dont have a virtual machine on their hard drive the best way to do that would be to make it an applet and sending the class and corresponding html file to the user. Then i would probably need a GUI so that the user can input the directory to look into and to create the new name for the files. Am I on the right track?
Athough i was certified in March i learned enough to pass the exam. But haven't had any real practice using it. So I'm not yet comfortable with
it. This is excellent proactice for me
david eberhardt
Ranch Hand

Joined: Jul 02, 2002
Posts: 158
I might suggest you send your friend some simple instructions for downlaoding the Java Runtime and instructions for which directory to place your java prgram when you send it.
Maybe you could create a sample directory on your own hard drive (simulating what he/she has and set it up so it would work same way for him/her when your friend goes to use it.
I would guess one screen shot of what to type into DOS command prompt might help.
Just one idea - don't forget that applets have restrictions on accessing hard drives.
Paul Ze

Joined: Mar 14, 2002
Posts: 18
Thanks good point. Like I said this is good practice for me and its good to get the feed back. I have added to the code above but am getting an expected identifier message in my IDE ( which
is visual J++)
Am I on the right track
import java.util.*;
public class Test
public static void main( String a[] )
File file = new File( "c:\\windows\\desktop\\" );
File[] files = file.listFiles(); // use listFiles(filter) if you need
File[] jpgfiles = file.listFiles
(new FilenameFilter(){
for(int i = 0;i<files.length();i++) {
StringTokenizer st1 =new StringTokenizer (files[i].getName(),".")
String tok1 = st1.nextToken();
String tok2 = st1.nextToken();
return true;
return false;

for( int i = 0; i < files.length; i++ )
if( !files[i].isDirectory() )
System.out.println( "File : "+files[i].getName() );
// instead of above do files[i].rename("string");
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 439
You should be using path as
File file = new File( "c:/windows/desktop/" );
instead !

Help gets you when you need it!
I agree. Here's the link:
subject: A project someone gave me...Renaming files
It's not a secret anymore!