SevenZip/SevenZipCompressor.cs
/// <summary>
///   Recursive function for adding files in directory
/// </summary>
/// <param name = "directory">Directory directory</param>
/// <param name = "files">List of files</param>
/// <param name = "searchPattern">Search string, such as "*.txt"</param>
Recursive function for adding files in directory
Recursive function for adding files in directory
private void AddFilesFromDirectory(string directory, ICollection<string> files, string searchPattern)
        {
            var di = new DirectoryInfo(directory);
            foreach (FileInfo fi in di.GetFiles(searchPattern))
            {
                if (!ScanOnlyWritable)
                {
                    files.Add(fi.FullName);
                }
                else
                {
                    try
                    {
                        using (fi.OpenWrite())
                        {
                        }
                        files.Add(fi.FullName);
                    }
                    catch (IOException)
                    {
                    }
                }
            }
            foreach (DirectoryInfo cdi in di.GetDirectories())
            {
                if (IncludeEmptyDirectories)
                {
                    files.Add(cdi.FullName);
                }
                AddFilesFromDirectory(cdi.FullName, files, searchPattern);
            }
        }
private void AddFilesFromDirectory ( string directory , ICollection < string > files , string searchPattern ) { var di = new DirectoryInfo ( directory ) ; foreach ( FileInfo fi in di . GetFiles ( searchPattern ) ) { if ( ! ScanOnlyWritable ) { files . Add ( fi . FullName ) ; } else { try { using ( fi . OpenWrite ( ) ) { } files . Add ( fi . FullName ) ; } catch ( IOException ) { } } } foreach ( DirectoryInfo cdi in di . GetDirectories ( ) ) { if ( IncludeEmptyDirectories ) { files . Add ( cdi . FullName ) ; } AddFilesFromDirectory ( cdi . FullName , files , searchPattern ) ; } }
Recursive function for adding files in directory
Recursive function for adding files in directory
directory
string
None
files
ICollection<string>
List of files
List of files
searchPattern
string
Search string, such as "*.txt"
Search string such as " * . txt "