import java.util.*; import java.io.*; public class FileTest { public static void main(String[] args) { // Create a directory File dir = new File("/path/to/MP3/"); // get the file names with path File[] filePath = dir.listFiles(); for(File fp :filePath) { // get the file name from the path String filename = fp.getName(); // String newname = filename.substring(3); File newfile = new File("/path/to/MP3/"+newname); fp.renameTo(newfile); } } }
[Java] Renaming a batch of files
Posted at
6/23/2011 09:41:00 AM
Due to some reason, the file names in my MP3 folder begin with two digits like this: 01 file.mp3. It is too tedious to rename them one by one since there are too many (hundreds of them). So I wrote a small program to remove the digits :) .
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment