Beispiel #1
0
        void CopyDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    CopyFile(fi, destDir);
                }
            }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForCopy(di, destDir, di.Name);
                    if (destSubDir != null)
                    {
                        CopyDirectory(di, destSubDir);
                    }
                }
            }

            dirs = null;
        }
Beispiel #2
0
        void CopyDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    CopyFile(fi, destDir);
                }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForCopy(di, destDir, di.Name);
                    if (destSubDir != null)
                        CopyDirectory(di, destSubDir);
                }

            dirs = null;
        }
Beispiel #3
0
        void MoveDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    MoveFile(fi, destDir);
                }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForMove(di, destDir, di.Name);
                    if (destSubDir != null)
                        MoveDirectory(di, destSubDir);
                }
            dirs = null;

            if (srcDir.Exists && srcDir.GetFileSystemInfos().Length == 0)
                srcDir.Delete();
        }
Beispiel #4
0
 private bool TryFetchLibraryDirectories(out IEnumerable <DirectoryEntry> result)
 {
     try
     {
         var librariesDirectory = new DirectoryInfoEx(KnownFolderIds.Libraries);
         result = librariesDirectory.GetDirectories().Select(x => GetDirectoryEntry(x, null));
         return(true);
     }
     catch (Exception e)
     {
         Logger.Warning(e, "Error occurred when trying to fetch library directories");
         result = null;
         return(false);
     }
 }
Beispiel #5
0
        private void ListDir(DirectoryInfoEx dir)
        {
            foreach (FileInfoEx fi in dir.GetFiles())
                if (_listFile && (String.IsNullOrEmpty(_fileMask) || IOTools.MatchFileMask(fi.Name, _fileMask)))
                    ReportWorkList(fi);

            DirectoryInfoEx[] dirs = dir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
            {
                if (_listDir)
                    ReportWorkList(di);
                ListDir(di);
                AddCompletedCount(di.FullName);
            }

            dirs = null;
        }
        public void CopyAllFix(string sourcePath, string destinationPath)
        {
            var directories = DirectoryInfoEx.GetDirectories(sourcePath, "*.*", SearchOption.AllDirectories);

            foreach (var srcDirPath in directories)
            {
                string tempDestPath = Uri.UnescapeDataString(srcDirPath.FullName.Replace(sourcePath, destinationPath, StringComparison.OrdinalIgnoreCase));
                if (DirectoryInfoEx.CreateDirectory(tempDestPath, out string errorMessage) != 0)
                {
                    ErrorLog.Inst.LogError(errorMessage);
                }
            }
            var files = DirectoryInfoEx.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);

            foreach (var srcFilePath in files)
            {
                string tempDestPath = Uri.UnescapeDataString(srcFilePath.FullName.Replace(sourcePath, destinationPath, StringComparison.OrdinalIgnoreCase));
                File.Copy(srcFilePath.FullName, tempDestPath, true);
            }
        }
Beispiel #7
0
        public static IEnumerable <FileInfoEx> EnumerateFilesEx(this DirectoryInfoEx path)
        {
            var queue = new Queue <DirectoryInfoEx>();

            queue.Enqueue(path);
            IEnumerable <FileSystemInfoEx> tmp;

            while (queue.Count > 0)
            {
                path = queue.Dequeue();
                try
                {
                    tmp = path.GetFiles();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    continue;
                }

                foreach (var t in tmp)
                {
                    yield return(t as FileInfoEx);
                }

                try
                {
                    tmp = path.GetDirectories();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    continue;
                }

                foreach (var subDir in tmp)
                {
                    queue.Enqueue(subDir as DirectoryInfoEx);
                }
            }
        }
        protected TreeNode CreateDirectoryNode(DirectoryInfoEx directoryInfo)
        {
            var directoryNode = new TreeNode(directoryInfo.Name);

            foreach (var directory in directoryInfo.GetDirectories())
            {
                var nodeItem   = CreateDirectoryNode(directory);
                var folderInfo = new FolderInfo(directory.FullName);
                folderInfo.CanDelete = true;
                nodeItem.Tag         = folderInfo;
                directoryNode.Nodes.Add(nodeItem);
            }
            foreach (var file in directoryInfo.GetFiles())
            {
                var nodeItem = new TreeNode(file.Name);
                var fileInfo = new FileInfo(file.FullName);
                fileInfo.CanDelete = true;
                nodeItem.Tag       = fileInfo;
                directoryNode.Nodes.Add(nodeItem);
            }
            return(directoryNode);
        }
        void MoveDirectory(DirectoryInfoEx srcDir, DirectoryInfoEx destDir)
        {
            FileInfoEx[] files = srcDir.GetFiles();
            AddTotalCount(files.Length);
            foreach (FileInfoEx fi in files)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(fi.FullName);
                    MoveFile(fi, destDir);
                }
            }
            files = null;

            DirectoryInfoEx[] dirs = srcDir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
            {
                if (!Aborted)
                {
                    CheckPause();
                    AddCompletedCount(di.FullName);
                    DirectoryInfoEx destSubDir = PrepateDirectoryForMove(di, destDir, di.Name);
                    if (destSubDir != null)
                    {
                        MoveDirectory(di, destSubDir);
                    }
                }
            }
            dirs = null;

            if (srcDir.Exists && srcDir.GetFileSystemInfos().Length == 0)
            {
                srcDir.Delete();
            }
        }
Beispiel #10
0
        private void ListDir(DirectoryInfoEx dir)
        {
            foreach (FileInfoEx fi in dir.GetFiles())
            {
                if (_listFile && (String.IsNullOrEmpty(_fileMask) || IOTools.MatchFileMask(fi.Name, _fileMask)))
                {
                    ReportWorkList(fi);
                }
            }

            DirectoryInfoEx[] dirs = dir.GetDirectories();
            AddTotalCount(dirs.Length);
            foreach (DirectoryInfoEx di in dirs)
            {
                if (_listDir)
                {
                    ReportWorkList(di);
                }
                ListDir(di);
                AddCompletedCount(di.FullName);
            }

            dirs = null;
        }
        public static List <IFileExplorerEntry> GetComputerDirectoryEntries()
        {
#if !NET45
            if (CoreHelper.RunningOnXP)
            {
                return
                    (DriveInfo.GetDrives()
                     .Select(x => GetDirectoryEntry(new DirectoryInfoEx(x.RootDirectory.FullName), null))
                     .Cast <IFileExplorerEntry>()
                     .ToList());
            }
#endif

            var entries = GetDirectoryEntries(DirectoryInfoEx.MyComputerDirectory);
            if (!CoreHelper.RunningOnWin8OrGreater)
            {
                bool success = false;
                try
                {
                    var librariesDirectory = new DirectoryInfoEx(KnownFolderIds.Libraries);
                    entries.InsertRange(0, librariesDirectory.GetDirectories().Select(x => GetDirectoryEntry(x, null)).Cast <IFileExplorerEntry>());
                    success = true;
                }
                catch (Exception)
                {
                    // ignored
                }

                if (!success)
                {
                    var musicEntry =
                        ExceptionUtilities.EatExceptions(
                            () =>
                            GetDirectoryEntry(
                                new DirectoryInfoEx(Environment.GetFolderPath(Environment.SpecialFolder.MyMusic)),
                                null));
                    if (musicEntry != null)
                    {
                        entries.Insert(0, musicEntry);
                    }

                    var documentsEntry =
                        ExceptionUtilities.EatExceptions(
                            () =>
                            GetDirectoryEntry(
                                new DirectoryInfoEx(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)),
                                null));
                    if (documentsEntry != null)
                    {
                        entries.Insert(0, documentsEntry);
                    }

                    var picturesEntry =
                        ExceptionUtilities.EatExceptions(
                            () =>
                            GetDirectoryEntry(
                                new DirectoryInfoEx(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures)),
                                null));
                    if (picturesEntry != null)
                    {
                        entries.Insert(0, picturesEntry);
                    }
                }
            }

            return(entries);
        }