다른 컴퓨터에서 열린 빈 공유 디렉터리를 삭제하려고합니다. 직접 삭제 (오른쪽 클릭 및 삭제)하면 제거됩니다.다른 컴퓨터에서 디렉터리를 연 경우 C# 코드를 사용하여 공유 폴더를 삭제하는 방법은 무엇입니까?
Stopwatch st = new Stopwatch();
st.Start();
while(true){
try
{
Directory.Delete(pathToDelete, true);
Console.WriteLine("Directory Deleted" + "Elapsed time:" + st.Elapsed.Seconds.ToString() + "sec");
break;
}
catch (Exception e)
{
if ((e is System.IO.IOException) || (e is System.UnauthorizedAccessException) ||
(e is System.Reflection.TargetInvocationException))
{
Console.WriteLine(e.ToString());
if (st.Elapsed > TimeSpan.FromMinutes(5))
{
Console.WriteLine("Can not delete directory ");
return;
}
Thread.Sleep(1000);
}
else
{
throw;
}
}
}
공유 폴더를 사용하는 동일한 컴퓨터 또는 다른 컴퓨터에서 열리는 디렉터리는 삭제되지 않습니다.
I found this 하지만 코드를 제대로 이해하지 못했습니다.
누구든지 더 좋은 방법을 제안합니까? 사전에 감사
삭제할 경로의 문자열 값은 무엇입니까? – Derek
앱이 관리자 권한으로 실행되고 있습니까 (Windows Vista 또는 7 인 경우)? 어떤 정확한 예외가 발생 했습니까? – Arran
pathToDelete에 "C : \ dir"을 사용했습니다. 공유 폴더 경로가 "\\ SPHVM-33821 \ dir" – naveejr