示例#1
0
 private DirectoryInfo ProcessingExceprionPath(string message, DirectoryInfo path, bool isRoot)
 {
     ExceptionProcessing.ErrorWriting(message);
     if (isRoot)
     {
         path = path.Parent;
     }
     currentPath = GetCurrentPath(path, null);
     exceptionPath.Add(path.FullName);
     return(new DirectoryInfo(GetParentPath(path, currentPath, null, false)));
 }
示例#2
0
        public List <FileModels> SearchFile(DirectoryInfo Path)
        {
            isTopDirectory++;
            if (Path.FullName == Path.Root.FullName)
            {
                isRootDir = true;
            }
            try
            {
                if (Path.FullName != exceptionPath.Where(exception => exception == Path.FullName).FirstOrDefault() &&
                    Path.FullName != distancePath.Where(path => path == Path.FullName).FirstOrDefault())
                {
                    distancePath.Add(Path.FullName);
                    SetCountFiles(Path.GetFiles(".", SearchOption.AllDirectories));
                    if (isTopDirectory == 1)
                    {
                        FileInfo[] files = Path.GetFiles();
                        foreach (FileInfo file in files)
                        {
                            listOfFiles.Add(new FileModels
                            {
                                PathName   = file.DirectoryName,
                                FileName   = file.Name,
                                FileLenght = file.Length / 1024
                            });
                        }
                    }
                }
                else
                {
                    CountFiles(Path);
                }
            }
            catch (UnauthorizedAccessException unEx)
            {
                CountFiles(
                    ProcessingExceprionPath(unEx.Message,
                                            new DirectoryInfo(unEx.Message.Substring(unEx.Message.IndexOf('\"')).
                                                              Substring(1).TrimEnd(new char[] { '"', '.' })), isRootDir));
            }
            catch (IOException ioEx)
            {
                ExceptionProcessing.ErrorWriting(ioEx.Message);
            }

            return(listOfFiles);
        }
示例#3
0
        public List <FolderModels> SearchDir(DirectoryInfo Path)
        {
            try
            {
                DirectoryInfo[] directories = CheckDirectory(Path);

                foreach (var directory in directories)
                {
                    AddFolder(directory, directory.Name);
                }
            }
            catch (Exception ex)
            {
                ExceptionProcessing.ErrorWriting(ex.Message);
                AddFolder(Path, ex.Message, true);
                listOfDirectory.Insert(0, listOfDirectory.Last());
                listOfDirectory.RemoveAt(listOfDirectory.Count - 1);
            }
            return(listOfDirectory);
        }
示例#4
0
 private string GetParentPath(DirectoryInfo Path, DirectoryInfo currentPath, string isLastFolder, bool isException)
 {
     try
     {
         if (Path.Parent == null)
         {
             parentPath = Path.Root.ToString();
         }
         if (isLastFolder != null)
         {
             if (Path.Parent.FullName != Path.FullName &&
                 Path.Parent.FullName != currentPath.FullName)
             {
                 parentPath = (Path.Parent.Root.Name == Path.Name) ? Path.Root.ToString() : Path.Parent.FullName;
             }
             if (Path.Parent.Parent != null)
             {
                 parentPath = (Path.Parent.Root.Name == Path.Name) ? Path.Root.ToString() : Path.Parent.Parent.FullName;
             }
             else
             {
                 parentPath = (Path.Parent.Root.Name == Path.Name) ? Path.Root.ToString() : Path.Parent.FullName;
             }
         }
         else
         {
             parentPath = (Path.Parent.Root.Name == Path.Name) ? Path.Root.ToString() : Path.Parent.FullName;
         }
         if (isException)
         {
             SearchDir(currentPath);
         }
     }
     catch (Exception ex)
     {
         ExceptionProcessing.ErrorWriting(ex.Message);
     }
     return(parentPath);
 }