Generally in Windows if the same file is copied under the same path, then a "-copy" file name appears after the filename, which now requires a filename in the format "(2)", especially when the document is exported, as follows:
/** * If a path already exists with a duplicate file name to be saved, add (1) after the new file .... * @param paths * @param filename * @param num * @return/public static string GetFileName (string
paths, String filename, int num) {file file = null;
string[] Filenamearr = Filename.split ("\;");
int length = Filenamearr.length;
String filenamestr= ""; The purpose here is to avoid the file name containing the "." When the filename repeats, an error occurs and we have to make sure that it is at the last "."
Preceded by "(2)" for (int i=0;i<=length-2;i++) {filenamestr = filenamestr+ filenamearr[i]+ ".";} if (num > 0) {file = new file (paths + "\" + filenamestr.substring (0, Filenamestr.length ()-1) + "( "+ string.valueof" (num = 1?)
2:num) + ")." + filenamearr[filenamearr.length-1]);
else {file = new file (paths + "\" + filename);
} if (File.exists ()) {return GetFileName (paths, filename, ++num); else {if (num > 0) {return paths + "\" + filenamestr.substring (0, Filenamestr.length ()-1) + "(" + string.valueof (num = 1?)
2:num) + ")." + filenamearr[filenamearr.length-1];
else {return paths + "\" + filename; }
}
}
The test results are as follows:
XXXX (2). xxx ">