Answer the question
In order to leave comments, you need to log in
C# How to delete an empty folder and subfolders?
Good afternoon! Tell me please!
The essence of the problem: my program sorts files. The input data is a folder in which there are subfolders in which files, files, I moved everything to the created folders, and the subfolders remained empty, how can I delete them ???
private void button3_Click_1(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
string filename;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
filename = folderBrowserDialog1.SelectedPath;
textBox3.Text = filename;
//string[] PathPhoto = Directory.GetFiles(filename);
//string[] PathPhoto2 = this.FileSearchFunction(filename);
string[] PathPhoto3 = Directory.GetFiles(filename,"*.*", SearchOption.AllDirectories);
foreach (string File2 in PathPhoto3)
{
int i = 0;
FileInfo fi = new FileInfo(File2);
i++;
FileStream foto = new System.IO.FileStream(File2, System.IO.FileMode.Open);
foto.Position = 0;
int t = foto.ReadByte();
//textBox4.Text = t.ToString();//
if ((t == 25)||(t==13))
{
using (Image img = System.Drawing.Image.FromStream(foto))
{
try
{
string GPS_TAG = filename + '\\' + @"GPS_TAG";
Directory.CreateDirectory(GPS_TAG);
foto.Close();
File.Move(File2, GPS_TAG + "\" + fi.Name);
continue;
}
catch
{
string GPS_NOT_TAG = filename + '\\' + @"GPS_NOT_TAG";
Directory.CreateDirectory(GPS_NOT_TAG);
foto.Close();
File.Move(File2, GPS_NOT_TAG + "\" + fi.Name);
}
}
}
}
}
textBox4.Text = "Finish";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question