This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
Author

A project someone gave me...Renaming files

Paul Ze
Greenhorn

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

Regds
Lupo


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
Paul Ze
Greenhorn

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
Paul,
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
Greenhorn

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.io.*;
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++) {
accept(file,files[i].getName()){
StringTokenizer st1 =new StringTokenizer (files[i].getName(),".")
String tok1 = st1.nextToken();
String tok2 = st1.nextToken();
if(tok2.equals("jpg")
return true;
else
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: 435
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: http://aspose.com/file-tools
 
subject: A project someone gave me...Renaming files
 
Similar Threads
How to write my resume (for Java developer) ?
renaming all files in one dir
I have an ASP.NET Application what is the processes that I must follow to convert it to JavaEE
File rename using Java API
how to convert a jar/war file of .class files to a folder containing .java files