Knowledge involved: string functions, File and Directory functions, Environment and some interface classes
The core code is as follows: very simple
// Clear logs
This. listBoxLog. Items. Clear ();
// Obtain all file names in the current path
String [] files = Directory. GetFiles (Environment. CurrentDirectory );
Foreach (String filename in files)
{
// The Last "\"
Int lastpath = filename. LastIndexOf ("\\");
// The Last "."
Int lastdot = filename. LastIndexOf (".");
// File Name Length
Int length = lastdot-lastpath-1;
// File directory string xx \
String beginpart = filename. Substring (0, lastpath + 1 );
// File name
String namenoext = filename. Substring (lastpath + 1, length );
// Extension
String ext = filename. Substring (lastdot );
If (length <3)
{
// Fill in three characters to form a new file name
String namenew;
If (length = 1)
Namenew = "00" + namenoext;
Else
Namenew = "0" + namenoext;
String fullnewname = beginpart + namenew + ext;
// Rename
File. Move (filename, fullnewname );
// Log
This. listBoxLog. Items. Add (namenoext + "--->" + namenew );
This. listBoxLog. SelectedIndex = this. listBoxLog. Items. Count-1;
}