My method get array of string as an argument, that represent paths to files and directories that my program have to delete. In foreach loop i have no idea if string represent path to file or directory, so i don't know which method i should use File.Delete() or Directory.Delete.
I create something like this but i think it could be done better :)
foreach (string path in deleteItems)
{
try
{
Directory.Delete(path, true);
}
catch (IOException)
{
try { File.Delete(path); }
catch (IOException e) { Console.WriteLine(e); }
}
}
Somebody have any idea how to do this code better?
Edit: or i think it could be better
if(File.Exists(path))
{
File.Delete(path);
continue;
}
if(Directory.Exists(path))
{
Directory.Delete(path);
continue;
}