Wednesday, January 24, 2018

RenameFilesInADirectory

package dummy;

import java.io.File;

public class RenameFilesInADirectory {

public static void main(String[] args) {
File directory = new File("D:\\Songs");
File[] files = directory.listFiles();
for(File file : files) {
// file.toString() gives absolute path to file
file.renameTo(new File(file.toString().replaceAll("_"," ")));
}
}

}