• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A project someone gave me...Renaming files

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Regds
Lupo
 
Paul Ze
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
}
}
}
 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be using path as
File file = new File( "c:/windows/desktop/" );
instead !
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic