Today learned the Java file operation, and then took the interest, wrote a can batch processing file naming small program, small program also has some imperfect place, but wins in interesting. For example, you can quickly change the files you don't want others to see ... Personal use, resulting in the consequences of data loss at your own risk.
ImportJava.io.File;Importjava.sql.Date;ImportJava.util.Scanner; Public classRenametool {BooleanUsedefaultname =false; BooleanUsedefaultsuffix =false; Scanner SC=NewScanner (system.in); //Renaming Methods Private voidReName () {String FilePath=GetPath (); String Diyname=Getdiyname (); String Setdiysuffix=Setdiysuffix (); String suffix=""; File File=NewFile (FilePath); File[] Fileslist=File.listfiles (); //determine if the name you want to DIY is empty, and the default is to rename it with a modified time if(diyname==NULL) {Usedefaultname=true; } if(Usedefaultname) {//name in modified time format//get the last modified time for(inti = 0; i < fileslist.length; i++) { LongLastModified =fileslist[i].lastmodified (); Date Date=NewDate (lastmodified); String Datename=date.tostring (); if(usedefaultsuffix) {//get the suffix name of each filesuffix=Getsuffix (Fileslist[i]); }Else{suffix=Setdiysuffix; } //File Name: path +\\+ name + suffix, note the file path is followed by a slashString newfilename=filepath+ "\\\\" +datename+ "-" + (i+1) +suffix; File NewFile=NewFile (NewFileName); Fileslist[i].renameto (NewFile); System.out.print (Fileslist[i].getname ()+ "modified to:"); System.out.println (NewFileName); } }Else{//name in a custom format for(intj = 0; J < Fileslist.length; J + +) { if(usedefaultsuffix) {//get the suffix name of each filesuffix=Getsuffix (Fileslist[j]); }Else{suffix=Setdiysuffix; } String NewFileName=filepath+ "\\\\" +diyname+ "-" + (j+1) +suffix; File NewFile=NewFile (NewFileName); System.out.print (Fileslist[j].getname ()+ "modified to:"); Fileslist[j].renameto (NewFile); System.out.println (NewFileName); } } } //Get file path PrivateString GetPath () {//There are transfer characters in Java and four slashes if you need to enter double slashesSystem.out.println ("Please enter the path of the file you want to bulk modify, format: C:\\\\xxx\\\\xx"); String Path=Sc.next (); SYSTEM.OUT.PRINTLN (path); //sc.close (); returnpath; } //A custom file name that can be selected by default as the modified time name PrivateString Getdiyname () {System.out.println ("Please enter the new file name format to be modified (enter y/y if you want to name the time):"); String NewName=Sc.next (); if(Newname.equals ("y") | | newname.equals ("y"))) { return NULL; } returnNewName; } //get suffix name method Privatestring getsuffix (file file) {string FileName=File.getname (); intLength =filename.length (); //use the "." On the far right. To find the suffix name intPointIndex = Filename.lastindexof (".")); String suffix=filename.substring (pointIndex, length); returnsuffix; } //If you do not want to use the previous suffix name, you can freely change PrivateString Setdiysuffix () {System.out.println ("Do you want to change the file suffix name uniformly?" Please enter the format (), otherwise please enter n/n: "); String input=Sc.next (); Sc.close (); if(Input.equals ("n") | | input.equals ("n")) ) {Usedefaultsuffix=true; return NULL; } Else{Usedefaultsuffix=false; Input="." +input; returninput; } } //provides static methods Public Static voidbegin () {Renametool T=NewRenametool (); T.rename (); } //Main function Public Static voidMain (string[] args) {Renametool T=NewRenametool (); T.rename (); }}
If you have time, you can write a small program to clean up the garbage file ~ ~ or some files can not be deleted directly, used for brute force deletion.
A Java-written batch rename file applet