ComponentPro UltimateZip

      FileInfoCollection Class

      See AlsoMembersMembers Options: Show AllLanguage Filter: AllSend comments on this topic to ComponentPro
      Defines a collection of FileInfoBase.

      Syntax

      public abstract class FileInfoCollection : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable

      Examples

      FTP Examples

      Shows how to use ListDirectory methods to retrieve list of files and directories in a directory.

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      
      ...
      
      // Create a new class instance.
      Ftp client = new Ftp();
      
      // Connect to the FTP server.
      client.Connect("myserver");
      
      // Authenticate.
      client.Authenticate("test", "test");
      
      // ... 
       
      // Get information of all files and directories in '/' remote dir. 
      foreach (FtpFileInfo info in client.ListDirectory("/"))
      {
          Console.WriteLine("Name: {0}, Permissions: {1}", info.Name, info.Permissions);
      }
      
      // Many FTP servers do not support ListDirectory with parameter method, Hence, we have to 
      // change the current directory before calling ListDirectory. 
      // Get names of all files and directories in '/my folder' remote dir.
      client.SetCurrentDirectory("/my folder");
      foreach (FtpFileInfo info in client.ListDirectory())
      {
          Console.WriteLine("Name: {0}, Permissions: {1}", info.Name, info.Permissions);
      }
      
      // List files with search condition. 
      // List all files that have .exe extension in "/" folder. 
      foreach (FtpFileInfo info in client.ListDirectory("/", new NameSearchCondition("*.exe")))
      {
          Console.WriteLine("Name: {0}, Permissions: {1}", info.Name, info.Permissions);
      }
      
      // Change the current directory before calling ListDirectory. 
      // Get names of files with .cs or .vb extensions and directories in '/my folder2' remote dir.
      client.SetCurrentDirectory("/my folder2");
      foreach (FtpFileInfo info in client.ListDirectory(new NameSearchCondition("*.cs;*.vb")))
      {
          Console.WriteLine("Name: {0}, Permissions: {1}", info.Name, info.Permissions);
      }
      
      // ... 
       
      // Disconnect.
      client.Disconnect();

      SFTP Examples

      Shows how to use ListDirectory methods to retrieve list of files and directories in a directory.

      using System;
      using ComponentPro.IO;
      using ComponentPro.Net;
      using System.Linq;
      
      ...
      
      // Create a new class instance.
      Sftp client = new Sftp();
      
      // Connect to the SFTP server.
      client.Connect("myserver");
      
      // Authenticate.
      client.Authenticate("test", "test");
      
      // ... 
       
      // Get information of all files and directories in '/' remote dir. 
      foreach (SftpFileInfo info in client.ListDirectory("/"))
      {
          Console.WriteLine("Name: {0}, UserId: {1}, Permissions: {2}, Size: {3}", info.Name, info.OwnerId, info.Permissions, info.Length);
      }
      
      // ... 
       
      // Disconnect.
      client.Disconnect();

      ZIP Examples

      Shows how to use ListDirectory methods to get a list of files and directories within an archive.

      using System;
      using ComponentPro.Compression;
      using ComponentPro.IO;
      
      ...
      
      // Open an existing file
      Zip zip = new Zip();
      
      zip.Open("test.zip");
      
      // List all .doc and .txt files in the current directory - root directory.
      ArchiveItemCollection col = (ArchiveItemCollection)zip.ListDirectory(new NameSearchCondition("*.doc;*.txt"));
      
      foreach (ArchiveItem archiveFile in col)
      {
          Console.WriteLine("File Name: " + archiveFile.Name);
          Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +
              archiveFile.LastWriteTime.ToShortTimeString());
          Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);
          Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);
          Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);
          Console.WriteLine("    CRC: " + archiveFile.Checksum);
          Console.WriteLine("    Stored Path: " + archiveFile.DirectoryName);
          Console.WriteLine("    Comment: " + archiveFile.Comment);
      }
      
      // List all files in 'my folder' directory.
      col = (ArchiveItemCollection)zip.ListDirectory("my folder");
      
      foreach (ArchiveItem archiveFile in col)
      {
          Console.WriteLine("File Name: " + archiveFile.Name);
          Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +
              archiveFile.LastWriteTime.ToShortTimeString());
          Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);
          Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);
          Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);
          Console.WriteLine("    CRC: " + archiveFile.Checksum);
          Console.WriteLine("    Stored Path: " + archiveFile.DirectoryName);
          Console.WriteLine("    Comment: " + archiveFile.Comment);
      }
      
      // List all .rtf files in 'my documents' directory.
      col = (ArchiveItemCollection)zip.ListDirectory("my folder", "*.rtf");
      
      foreach (ArchiveItem archiveFile in col)
      {
          Console.WriteLine("File Name: " + archiveFile.Name);
          Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +
              archiveFile.LastWriteTime.ToShortTimeString());
          Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);
          Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);
          Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);
          Console.WriteLine("    CRC: " + archiveFile.Checksum);
          Console.WriteLine("    Stored Path: " + archiveFile.DirectoryName);
          Console.WriteLine("    Comment: " + archiveFile.Comment);
      }
      
      zip.Close();

      Inheritance Hierarchy

         ComponentPro.IO.ComponentPro.IO.FileInfoCollection

      Framework

      .NET Compact Framework.NET Compact Framework

      Supported version: 2.0, 3.5, and 3.9
      Assembly: ComponentPro.FileSystem.CF (in ComponentPro.FileSystem.CF.dll)

      .NET Framework.NET Framework

      Supported version: 2.0, 3.0, 3.5, 4.0, 4.5.x, 4.6.x and later
      Assembly: ComponentPro.FileSystem (in ComponentPro.FileSystem.dll)

      Xamarin AndroidXamarin Android

      Supported version: 2.3 and later
      Assembly: ComponentPro.FileSystem.Android (in ComponentPro.FileSystem.Android.dll)

      Xamarin iOSXamarin iOS

      Supported version: 5.1.x and later
      Assembly: ComponentPro.FileSystem.iOS (in ComponentPro.FileSystem.iOS.dll)

      See Also