Beispiel #1
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();
         }
     }
 }
Beispiel #2
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());
        }