Exemple #1
0
        private void RecurseDirectories(string path)
        {
            try
            {
                List <string> directories = Directory.GetDirectories(path).ToList();

                foreach (string directory in directories)
                {
                    _folders.Insert(0, directory);
                    UpdateFoldersIdentifiedCount();
                    UpdateFolersLeftToProcessCount();

                    RecurseDirectories(directory);
                }
            }
            catch (UnauthorizedAccessException exc)
            {
                if (_getFileDetails)
                {
                    FileDetails details = new FileDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path  = path;
                    SaveFileDetailsToFile(details);
                }
                else if (_getFolderSecurityDetails)
                {
                    FolderSecurityDetails details = new FolderSecurityDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path  = path;
                    SaveFolderSecurityDetailsToFile(details);
                }
            }
        }
Exemple #2
0
 private void SaveFileDetailsToFile(FileDetails details)
 {
     using (StreamWriter writer = File.AppendText(_outputFileName))
     {
         writer.WriteLine(details.ToCsvFormattedString());
     }
 }
Exemple #3
0
        private void GetFileDetails(string path)
        {
            List <string> files;

            try
            {
                files = Directory.GetFiles(path).ToList();
            }
            catch (UnauthorizedAccessException exc)
            {
                FileDetails details = new FileDetails();
                details.Error = "Exception - Folder Access Exception";
                details.Path  = path;
                SaveFileDetailsToFile(details);
                return;
            }
            catch (DirectoryNotFoundException exc)
            {
                FileDetails details = new FileDetails();
                details.Error = "Exception - Directory Not Found";
                details.Path  = path;
                SaveFileDetailsToFile(details);
                return;
            }

            foreach (string file in files)
            {
                FileDetails details = new FileDetails();

                try
                {
                    details.Name = Path.GetFileName(file);
                    details.Path = Path.GetFullPath(file);
                    FileInfo fileInfo = new FileInfo(file);
                    details.SizeInBytes      = fileInfo.Length;
                    details.CreationDate     = fileInfo.CreationTime;
                    details.LastAccessDate   = fileInfo.LastAccessTime;
                    details.LastModifiedDate = fileInfo.LastWriteTime;

                    SaveFileDetailsToFile(details);

                    long fileCount = Convert.ToInt64(lblFilesIdentified.Text.Replace(",", string.Empty));

                    lblFilesIdentified.Text = (fileCount + 1).ToString("N0");
                }
                catch (PathTooLongException exc)
                {
                    FileDetails fileDetails = new FileDetails();
                    fileDetails.Error = "Exception: Path Too Long Exception: ";
                    fileDetails.Path  = file;
                    SaveFileDetailsToFile(details);
                }
            }
        }
        private void RecurseDirectories(string path)
        {
            try
            {

                List<string> directories = Directory.GetDirectories(path).ToList();

                foreach (string directory in directories)
                {
                    _folders.Insert(0, directory);
                    UpdateFoldersIdentifiedCount();
                    UpdateFolersLeftToProcessCount();
                    
                    RecurseDirectories(directory);
                }
            }
            catch (UnauthorizedAccessException exc)
            {
                if (_getFileDetails)
                {
                    FileDetails details = new FileDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path = path;
                    SaveFileDetailsToFile(details);
                }
                else if (_getFolderSecurityDetails)
                {
                    FolderSecurityDetails details = new FolderSecurityDetails();
                    details.Error = "Exception - Folder Access Exception";
                    details.Path = path;
                    SaveFolderSecurityDetailsToFile(details);
                }
            }
        }
 private void SaveFileDetailsToFile(FileDetails details)
 {
     using (StreamWriter writer = File.AppendText(_outputFileName))
     {
         writer.WriteLine(details.ToCsvFormattedString());
     }
 }
        private void GetFileDetails(string path)
        {
            List<string> files;

            try
            {
                files = Directory.GetFiles(path).ToList();
            }
            catch (UnauthorizedAccessException exc)
            {
                FileDetails details = new FileDetails();
                details.Error = "Exception - Folder Access Exception";
                details.Path = path;
                SaveFileDetailsToFile(details);
                return;
            }
            catch (DirectoryNotFoundException exc)
            {
                FileDetails details = new FileDetails();
                details.Error = "Exception - Directory Not Found";
                details.Path = path;
                SaveFileDetailsToFile(details);
                return;
            }

            foreach (string file in files)
            {
                FileDetails details = new FileDetails();

                try
                {
                    details.Name = Path.GetFileName(file);
                    details.Path = Path.GetFullPath(file);
                    FileInfo fileInfo = new FileInfo(file);
                    details.SizeInBytes = fileInfo.Length;
                    details.CreationDate = fileInfo.CreationTime;
                    details.LastAccessDate = fileInfo.LastAccessTime;
                    details.LastModifiedDate = fileInfo.LastWriteTime;

                    SaveFileDetailsToFile(details);

                    long fileCount = Convert.ToInt64(lblFilesIdentified.Text.Replace(",", string.Empty));

                    lblFilesIdentified.Text = (fileCount + 1).ToString("N0");

                }
                catch (PathTooLongException exc)
                {
                    FileDetails fileDetails = new FileDetails();
                    fileDetails.Error = "Exception: Path Too Long Exception: ";
                    fileDetails.Path = file;
                    SaveFileDetailsToFile(details);

                }
            }
        }