원격 컴퓨터에서 XML 파일이 들어있는 디렉터리를 삭제하려고합니다. 내 코드가 제대로 컴파일되고 실행되지만 지정한 경로에서 XML 파일 목록을 가져 오면 아무 것도 반환하지 않습니다. 나는 현명한 무언가를 놓치고 있습니까?원격 컴퓨터에서 파일 삭제
나는 나 자신과 다른 컴퓨터로 로그온 한 다른 컴퓨터에서 로그온 한 컴퓨터에서 실행했습니다. 두 계정 모두 XML 파일이 들어있는 디렉토리를 완전히 제어 할 수 있습니다.
.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());
}
}
}
원격 경로 (\\ server \ folderx \ foldery)를 사용하고 있습니다. 이 파일들은 Google 서버 중 하나에 저장되어 있으며 프로그램은 매우 구체적입니다. 난 단지 특정 디렉토리에서 작동하도록하고 모든 디렉토리는 같은 형식을 가지고 있습니다. –