示例#1
0
 private void scan(string path)
 {
     if (LongDirectory.Exists(path))
     {
         scannedFiles++;
         foreach (string sub in LongDirectory.GetDirectories(path))
         {
             if (formClosing)
             {
                 break;
             }
             scan(sub);
         }
         foreach (string file in LongDirectory.GetFiles(path))
         {
             if (formClosing)
             {
                 break;
             }
             scan(file);
         }
     }
     else if (LongFile.Exists(path))
     {
         scannedFiles++;
     }
     Application.DoEvents();
 }
示例#2
0
 private static void DeleteDirectories(string[] directories)
 {
     foreach (string directory in directories)
     {
         string[] files = LongDirectory.GetFiles(directory, null, System.IO.SearchOption.TopDirectoryOnly);
         foreach (string file in files)
         {
             LongFile.Delete(file);
         }
         directories = LongDirectory.GetDirectories(directory, null, System.IO.SearchOption.TopDirectoryOnly);
         DeleteDirectories(directories);
         bool ok = NativeMethods.RemoveDirectory(GetWin32LongPath(directory));
         if (!ok)
         {
             ThrowWin32Exception();
         }
     }
 }
示例#3
0
        public static string[] GetFiles(string path, string searchPattern, System.IO.SearchOption searchOption)
        {
            searchPattern = searchPattern ?? "*";

            var files = new List <string>();
            var dirs  = new List <string> {
                path
            };

            if (searchOption == SearchOption.AllDirectories)
            {
                //Add all the subpaths
                dirs.AddRange(LongDirectory.GetDirectories(path, null, SearchOption.AllDirectories));
            }

            foreach (var dir in dirs)
            {
                NativeMethods.WIN32_FIND_DATA findData;
                IntPtr findHandle = NativeMethods.FindFirstFile(System.IO.Path.Combine(GetWin32LongPath(dir), searchPattern), out findData);

                try
                {
                    if (findHandle != new IntPtr(-1))
                    {
                        do
                        {
                            if ((findData.dwFileAttributes & System.IO.FileAttributes.Directory) == 0)
                            {
                                string filename = System.IO.Path.Combine(dir, findData.cFileName);
                                files.Add(GetCleanPath(filename));
                            }
                        } while (NativeMethods.FindNextFile(findHandle, out findData));
                        NativeMethods.FindClose(findHandle);
                    }
                }
                catch (Exception)
                {
                    NativeMethods.FindClose(findHandle);
                    throw;
                }
            }

            return(files.ToArray());
        }
示例#4
0
        private bool delete(string path)
        {
            bool result = false;

            if (LongDirectory.Exists(path))
            {
                string[] subs = LongDirectory.GetDirectories(path);
                foreach (string sub in subs)
                {
                    if (formClosing)
                    {
                        break;
                    }
                    delete(sub);
                }
                string[] files = LongDirectory.GetFiles(path);
                foreach (string file in files)
                {
                    if (formClosing)
                    {
                        break;
                    }
                    delete(file);
                }
                try
                {
                    LongDirectory.Delete(path);
                    result = true;
                }
                catch (Exception ex)
                {
                    if (ex.HResult == -2147024751 || ex.HResult == -2147467259)
                    {
                        txtLog.AppendText(string.Format("Directory is not empty: {0}\r\n", path));
                    }
                    else
                    {
                        txtLog.AppendText(string.Format("{0}\r\n", ex.Message));
                    }
                    result = false;
                }
                toolStripProgressBar1.Value++;
                Application.DoEvents();
            }
            else if (LongFile.Exists(path))
            {
                try
                {
                    LongFile.Delete(path);
                    result = true;
                }
                catch (Exception ex)
                {
                    txtLog.AppendText(string.Format("{0}: {1}\r\n", ex.Message, path));
                    result = false;
                }
                toolStripProgressBar1.Value++;
                Application.DoEvents();
            }
            return(result);
        }