0
I want to make a program that checks if any file is null but this casting an exception, which is wrong in my code?:
static List<string> GetFiles(string path)
{
string[] directories = Directory.GetDirectories(path);
List<string> filesList = new List<string>();
foreach(string directory in directories)
{
string[] files = Directory.GetFiles(directory);
foreach(string f in files)
{
filesList.Add(directories + "\\" + f);
}
}
return filesList;
}
private void txtB_Path_TextChanged(object sender, EventArgs e) { }
private void bt_Start_Click(object sender, EventArgs e)
{
List<string> files = GetFiles(txtB_Path.Text);
List<string> nullFiles = new List<string>();
List<string> nullFilesDirectories = new List<string>();
try
{
foreach (string item in files)
{
byte[] fileBytes = File.ReadAllBytes(item);
foreach (byte bytes in fileBytes)
{
if (bytes == 0)
{
nullFiles.Add(fileBytes.ToString());
nullFilesDirectories.Add(item);
}
}
}
lb_NullFiles.Text = nullFiles.Count.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
lb_NullFiles.Text = "0";
}
try {
if (chckB_DeleteNullFiles.Checked)
{
foreach (string file in nullFilesDirectories)
{
File.Delete(file);
}
}
}
catch
{
MessageBox.Show("Could not delete files");
}
lb_Files.Text = files.Count.ToString();
}
You can speak in Portuguese if this is your "mother language";) Our official language is Portuguese.
– user28595
ok thanks guy ! (Agr q vi q tava no portugues kkkk)
– Artur Ricardo
Forgot to translate the title.
– Sam
Thank you, I’ve already edited and I’m going to do the tour
– Artur Ricardo
Lines 48-70 Exception: "No support for the given path format"
– Artur Ricardo
Instead of commenting on things relevant to the question, include it in the question itself. It will become clearer.
– Sam
Ss, I’m new here, qlqr tip q have to make it clear...
– Artur Ricardo