im making an app to sort the files in a directory into the same order as a list box and now im trying to make it sort the file on the fat32 file table but cant find out how or if i can do this on c# can anyone help me heres the code that adds the files to the list box
private void openfolder()
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
DirectoryInfo dinfo = new DirectoryInfo(folderBrowserDialog1.SelectedPath);
FileInfo[] Files = dinfo.GetFiles("*.*");
foreach (FileInfo file in Files)
{
listBox1.Items.Add(file.Name);
}
}
}
Ok. So it goes something like this:
var path = @"U:\";
var di = new DirectoryInfo(path);
var files = di.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly).ToList();
var newDirPath = Path.Combine(path,Guid.NewGuid().ToString("N"));
di = Directory.CreateDirectory(newDirPath);
files.ForEach(f => f.MoveTo(Path.Combine(newDirPath, f.Name)));
files=di.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly)
.OrderBy(f=>f.CreationTime) //sort here
.ToList();
files.ForEach(f=>f.MoveTo(Path.Combine(path,f.Name)));
Directory.Delete(newDirPath);
Your objection to moving files is ill-founded. The move operation does not copy data. It merely changes the allocation table.
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.