I'm trying to delete a directory that contains XML files from a remote computer. My code compiles and runs fine, but when I go to get a list of XML files in the path I specify, it is not returning anything. Am I missing something permission wise? I have ran it from my computer logged on as myself and from another computer logged on as a different user. Both accounts have full control over the directory that contains the XML files.
I'm using .NET 2.0.
static void Main(string[] args) {
string directory, ext = ".xml"; // have tried xml and .xml
if (args.Length != 1) {
// do absolutely nothing if we do not exactly 1 argument
} else {
Console.WriteLine("Argument accepted.");
directory = args[0];
// make sure the directory passed is valid
if (ValidateDirectory(directory)) {
Console.WriteLine("Directory is valid.");
DeleteFiles(directory, ext);
}
}
Console.WriteLine("Done.");
}
static bool ValidateDirectory(string d) {
return Regex.IsMatch(d, @""); // I removed my regex - it validates properly
}
static void DeleteFiles(string d, string ext) {
DirectoryInfo di;
FileInfo[] fi;
di = new DirectoryInfo(d);
fi = di.GetFiles(ext);
Console.WriteLine("Number of files = " + fi.Length + ".");
foreach (FileInfo f in fi) {
try {
Console.WriteLine(f.FullName);
f.Delete();
} catch (Exception ex) {
// do nothing when there is an exception
// just do not want it to quit
Console.WriteLine(ex.ToString());
}
}
}