Пример #1
0
 private static void DeleteDirectoriesRecrusive(string[] directories)
 {
     foreach (string directory in directories)
     {
         var files = Win32LongPathDirectory.GetFiles(GetWin32LongPath(directory), null, System.IO.SearchOption.TopDirectoryOnly);
         foreach (string file in files)
         {
             Win32LongPathFile.Delete(GetWin32LongPath(file));
         }
         directories = Win32LongPathDirectory.GetDirectories(directory, null, System.IO.SearchOption.TopDirectoryOnly);
         DeleteDirectoriesRecrusive(directories);
         bool ok = Win32FileSystem.RemoveDirectory(GetWin32LongPath(directory));
         if (!ok)
         {
             ThrowWin32Exception();
         }
     }
 }
Пример #2
0
        public static void Delete(string path, bool recursive = false)
        {
            if (!recursive)
            {
                //handle read only
                //Win32LongPathFile.SetAttributes(path, System.IO.FileAttributes.Normal);
                if (!Win32FileSystem.RemoveDirectory(GetWin32LongPath(path)))
                {
                    ThrowWin32Exception();
                }
            }
            else
            {
                var longPath = new string[] { GetWin32LongPath(path) };
                DeleteDirectoriesRecrusive(longPath);
            }

            //if (path.Length < MAX_PATH && !recursive)
            //{
            //    //Handle read only
            //    //            SetFileAttribute(directory, FileAttributes.Normal);
            //    System.IO.Directory.Delete(path, recursive);
            //}
            //else
            //{
            //    if (!recursive)
            //    {
            //        //handle read only
            //        //            SetFileAttribute(directory, FileAttributes.Normal);
            //        bool ok = Win32FileSystem.RemoveDirectory(GetWin32LongPath(path));
            //        if (!ok) ThrowWin32Exception();
            //    }
            //    else
            //    {
            //        DeleteDirectories(new string[] { GetWin32LongPath(path) });
            //    }
            //}
        }