This topic demonstrates how to list the contents of a folder. With Xceed's FileSystem-based products, a folder is a folder: it does not matter if it is located within a zip file, on disk or in memory.
Basic steps
To list the contents of a folder, the following steps must be performed:
-
Retrieve a reference to a folder using an AbstractFolder-derived class appropriate for the folder you need to work with, such as DiskFolder, ZippedFolder, ZipArchive, MemoryFolder, IsolatedFolder, FtpFolder, etc.
-
Call the GetFiles method to retrieve a listing of the files contained within the folder.
-
You can now loop through the files and extract the desired information.
Demonstration
This example demonstrates how to list the contents of a folder located on disk.
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
Things you should consider
The main questions you should ask yourself when listing the contents of a folder are:
-
Do you want to filter (specify specific files and folders) the items that are to be listed? Use filters.
-
Do you also want to retrieve a listing of the folders? Use the GetFolders method.
-
Do you want to retrieve a listing of both files and folders? Use the GetItems method.
-
Do you want to retrieve a reference to a single file or folder? Use the GetFile or GetFolder methods.
-
Do you want to display the status of the operation? See the Events topic.
-
Do you want to filter your list of files or folders? See the Filters topic.