FileSystem is a class which will enable you to quickly


FileSystem is a class which will enable you to quickly

.

 

FileSystem is a class which will enable you to quickly, easily and efficiently get the content of a given directory. A file system class is an essential part of any code library. Every application does some sort of file interaction, and if you create a nice class to handle interaction between your application and the file system then it will make life a bit easier and you will not need to fd yarn recreate the wheel a hundred times for each project. Here I will try to provide such a class that you can use in your project. This article is an extension of another article (Automating MS Excel 2003 using Visual Studio .NET), which are both part of the same project. However, I have done some modifications to the code provided here that will make it more generic.

 

So there are two section to this article, one which will cover the FileSystem class and the other that will cover the application that will use the class to demonstrate some of its features.

Background No background needed, just be familiar with the C# language, threads, and FileSystemObject.

Using the code Here I will try to cover the FileSystem class. This class is really simple and self explanatory. It is also well documented. But let's go over it in any case. So we have a class named FileSystem that is used to do some file system operations. Let's take a look at the class:

FileSystem Class

Alright, so we have several files that are used internally by the class. Six of them are available as properties that can be accessed at runtime and a few are set during initialization, i.e., sourcePath and destinationPath.

COPY_STATUS - is used to notify the parent thread about the status of the copy thread. FILE_FILTER - is used for filtering file types. i.e., *.xml, *.cs, *.xls, etc... if left null it will behave as *.* NUMBER_OF_DIRECTORIES - returns number of directories in the search. NUMBER_OF_FIELS - returns number of files in the search. ROOT_PATH - gets or sets the root path to be used for navigation. STATUS - is the status of the main thread in the FileSystem class. You also can notice that there are three private methods that are used internally by the class. Two of those methods are used to start a particular thread. And the RecursiveDirectoryNavigation() method is used by the main thread of the FileSystem class to do the navigation, given the rootPath.

To use the copy method of the class you will use one of the two overloaded functions for the constructor and then will call the copyDirectory method which will initiate the startCopyThread to perform the operation. From your main thread you can use the COPY_STATUS property to check on the thread for your next program logic if any.

 

7 Views