There are a bunch of files in a bunch of folders. The names of these files contain special fields such as #. Through this method, the names of these files can be changed uniformly
Note: The red area can be modified to logically process the file
public void listDirectory (string path,char putChar)
{
DirectoryInfo theFolder=new DirectoryInfo(path) //Folder path
// loop through the file
foreach(FileInfo nextFile in theFolder.GetFiles()){
string filename = NextFile.FullName;//File name
if(filename.Contains(putChar)){//Whether the character is included
string newFileName=filename;
newFileName=newFileName.Replace(putChar,'x')//Change the offending character to other characters, which can also be passed in as a parameter
NextFile.MoveTo(newFileName);//Move the file to this directory
}
}
//traverse the folder
foreach(DirectoryInfo newFolder in theFolder.GetDirectories())
{
listDirectory(newFolder.FullName,putChar);//Recursive processing
}
}
File processing has always been a hassle, especially importing data from txt files or importing data from shapefiles. If there is a multi-threaded processing method in the courtyard, I hope we can communicate.