Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Date;
- import java.text.SimpleDateFormat;
- public class Renamer {
- public static void main(String[] args) {
- String filesDir = "C:\\OriginalFiles";
- String convertedDir = "C:\\RenamedFiles";
- String[] files = new java.io.File(filesDir).list();
- File oldFile[] = new File(filesDir).listFiles(), dest = new File(convertedDir);
- for( int i = 0; i < files.length; i++ ) {
- Date todaysDate = new java.util.Date();
- SimpleDateFormat formatter = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss");
- String formattedDate = formatter.format(todaysDate);
- int extdotpos = files[i].lastIndexOf(".");
- String newName = formattedDate + files[i].substring(extdotpos);
- oldFile[i].renameTo(new File(dest, newName));
- System.out.println(files[i] + " > " + newName);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) { }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement