I have recently disabled 8.3 file names on my NTFS volume and noticed a significant decrease (it only takes 25% as much time now) in the amount of time it takes to enumerate a new directory with a very large amount of files. However, this does not apply to existing files.
To change that, I want to create an exe that will recursively go through all of the files on the drive that are not in system folders, move them to a temp directory, and move them back in order to force the 8.3 file name removal on them. I already know how to enumerate through the files of a directory and perform this action on each of them, but I'm not quite sure how to get a list of all the directories on the disk without any system directories included. Is there an Attribute I can look for within a DirectoryInfo object? If not, what other approach can I take to accomplish this?
Here you go. I believe this is what you are after... See FileAttributes for more information.
public void RecursivePathWalk(string directory)
{
string[] filePaths = Directory.GetFiles(directory);
foreach (string filePath in filePaths)
{
if (IsSystem(filePath))
continue;
DoWork(filePath);
}
string[] subDirectories = Directory.GetDirectories(directory);
foreach (string subDirectory in subDirectories)
{
if (IsSystem(subDirectory))
continue;
RecursivePathWalk(subDirectory);
}
}
public void DoWork(string filePath)
{
//Your logic here
}
public bool IsSystem(string path)
{
FileAttributes attributes = File.GetAttributes(path);
return (attributes & FileAttributes.System) != 0;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.