Last active
August 29, 2015 13:57
-
-
Save mehmetbebek/9803937 to your computer and use it in GitHub Desktop.
Rename a File With Explorer Right Click
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
[HKEY_CLASSES_ROOT\*\shell\mgnfcnt] | |
@="Random Rename" | |
[HKEY_CLASSES_ROOT\*\shell\mgnfcnt\command] | |
@="java -jar \"C:\\mgnfcnt.jar\" \"%1\"" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This package is triggered by shell(regedit) command when user select any file and | |
//right clicked it user sees Random Rename option.Put this jar file under C directly | |
//Please run reg file before fire this jar file | |
package rename; | |
import java.io.File; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
public class rename { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
File oldfile; | |
File newfile; | |
try { | |
String loc = null; | |
for (String s : args) { | |
loc = s; | |
} | |
String path = loc; | |
File oldFile = new File(path); | |
String fileName = oldFile.getName(); | |
String filepath = oldFile.getParent(); | |
String extension = ""; | |
String newFileName = "AutoNamedFile_"; | |
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss"); | |
Date date = new Date(); | |
newFileName += dateFormat.format(date); | |
int i = fileName.lastIndexOf('.'); | |
int p = Math.max(fileName.lastIndexOf('/'), | |
fileName.lastIndexOf('\\')); | |
if (i > p) { | |
extension = fileName.substring(i + 1); | |
} | |
extension = extension.equals("") ? extension : ("." + extension); | |
oldfile = new File(path); | |
newfile = new File(filepath + "\\" + newFileName + extension); | |
oldfile.renameTo(newfile); | |
} catch (Exception ex) { | |
JOptionPane.showMessageDialog(null, "Rename failed \n" + ex); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment