« Home 

Saturday, March 04, 2006 

Program to Rename Files in a given Directory

import java.io.File;

/**
* Program to rename the files in a given Floder
*
* @author vsphanindra
*/
public class Rename {
public static void main(String[] argv) {
if (argv.length != 1) { // no progname in argv[0]
System.err.println("usage: Empty dirname");
System.exit(1);
}

File dir = new File(argv[0]);
if (!dir.exists()) {
System.out.println(argv[0] + " does not exist");
return;
}
String[] info = dir.list();
for (int i = 0; i < info.length; i++) {
File n = new File(argv[0] + dir.separator + info[i]);
/* this is the place where we will change the name of the file's
with the extension we wishin the given folder*/
String str= argv[0] + dir.separator+"Scene"+i+".jpg";
n.renameTo(new File(str));
}
}
}

/* javac Rename.java */

/*java Rename "absolute path of the directory which you want to change the file name in" */

About me

  • I'm phanindra
  • From Hyderabad, Andhra Pradesh, India
  • An Alumini of JNTU Hyd into happening IT industry...
My profile

Previous posts


Visitors
Bloggeries Blog Directory BlogRankings.com singapore blog directory blog search directory
Google
 
Web conceptoftheday.blospot.com