示例#1
0
 /// <summary>
 /// Run a full scan on from <see cref="StartDirectory"/> find all directories, calculates tha directory size and retrieves the file found extensions
 /// If <see cref="DeepSearch"/> is enable retrieves all sub directories and all files contained in
 /// the root directory.
 /// </summary>
 /// <param name="foundExtensions">The found extensions.</param>
 /// <param name="directorySize">Size of the directory.</param>
 /// <param name="filter">The scanner search filter.</param>
 /// <param name="findFileAction">Defines a costume action when a file is found.</param>
 /// <param name="findDirectoryAction">Defines a costume action when a directory is found.</param>
 public void FullScan(out String[] foundExtensions, out AerithSize directorySize,
                      AerithFilter filter = null, FileScannerHandler findFileAction = null, DirectoryScannerHandler findDirectoryAction = null)
 {
     try
     {
         List <String> extensions = new List <string>();
         long          size       = 0;
         this.Find(filter,
                   //Se agregá al escaneo la recolección de extensiones y el calculo del tamaño del archivo
                   (ref Object input, DirectoryInfo startDirectory, FileInfo currentFile) =>
         {
             string ext = currentFile.Extension.Replace(".", "").ToUpper();
             if (!extensions.Contains(ext))
             {
                 extensions.Add(ext);
             }
             size += currentFile.Length;
             if (findFileAction != null)
             {
                 findFileAction(ref input, startDirectory, currentFile);
             }
         }, findDirectoryAction);
         directorySize   = size.GetSizeFromBytes();
         foundExtensions = extensions.ToArray();
     }
     catch (Exception)
     {
         throw;
     }
 }
示例#2
0
 /// <summary>
 /// Find all the files and directories from <see cref="StartDirectory"/>
 /// If <see cref="DeepSearch"/> is enable retrieves all sub directories and all files contained in
 /// the root directory.
 /// </summary>
 /// <param name="filter">The scanner search filter.</param>
 /// <param name="findFileAction">Defines a costume action when a file is found.</param>
 /// <param name="findDirectoryAction">Defines a costume action when a directory is found.</param>
 /// <exception cref="BlackMateriaException"></exception>
 public void Find(AerithFilter filter = null, FileScannerHandler findFileAction = null, DirectoryScannerHandler findDirectoryAction = null)
 {
     try
     {
         List <FileInfo>      files = new List <FileInfo>();
         List <DirectoryInfo> dirs  = new List <DirectoryInfo>();
         Object scnInput            = new Object[] { files, dirs };
         this.Scan(ref scnInput, this.StartDirectory,
                   //Recolección de archivos
                   (ref Object input, DirectoryInfo startDirectory, FileInfo currentFile) =>
         {
             if ((filter == null) || (filter != null && filter.IsFileValid(currentFile)))
             {
                 var fList = (scnInput as Object[])[0] as List <FileInfo>;
                 fList.Add(currentFile);
                 if (findFileAction != null)
                 {
                     findFileAction(ref input, startDirectory, currentFile);
                 }
             }
         },
                   ////Recolección de directorios
                   (ref Object input, DirectoryInfo startDirectory, DirectoryInfo currentDirectory) =>
         {
             if ((filter == null) || (filter != null && filter.IsDirectoryValid(currentDirectory)))
             {
                 var dList = (scnInput as Object[])[1] as List <DirectoryInfo>;
                 dList.Add(currentDirectory);
                 if (findDirectoryAction != null)
                 {
                     findDirectoryAction(ref input, startDirectory, currentDirectory);
                 }
             }
         }, this.DeepSearch);
         this._Files       = files.ToArray();
         this._Directories = dirs.ToArray();
     }
     catch (Exception exc)
     {
         if (!OmitErrors)
         {
             throw exc;
         }
     }
 }