Spiga

Cool File System Class with Thread Support - Easy To Use

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 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.

To use the code, all you need is the following:

CoolFileSystem.FileSystem fileSystem

= FileSystem(@root); That's all it takes! Below you will find code snippets. Of course the full source is available for you to download. Below you can see a portion of the class source.

namespace CoolFileSystem {

public class FileSystem

{

// Used to hold root directory. Start point for the search.

private string rootPath;

...

// Used to filter filename when doing

// the search. By default it is set to "*.xls".

// Can be changed using the FILE_FILTER property.

private string fileFilter = "*.*";

// File list is used internally. It is a list

// of all files found given the search

// criteria. Automatically adjust itself. Default size 500.

private ArrayList fileList = new ArrayList(500);

// Used to store directories found under

// the rootPath. It contains objects of type

// DirectoryStructure which hold

// the Directory Information with a list of files

// under the current directory.

private ArrayList directoryList = new ArrayList(500);

// Used for navigation thru the directory structure.

private Thread mainThread;

...

...

public FileSystem(string path)

{

rootPath = path;

mainThread = new Thread(new ThreadStart(startThread));

mainThread.Start();

}

private void startThread()

{

DirectoryInfo di = new DirectoryInfo(rootPath);

RecursiveDirectoryNavigation( di );

}

...

...

#region RECURSIVE DIRECTORY NAVIGATION

[STAThread]

private void RecursiveDirectoryNavigation( DirectoryInfo di )

{

try

{

// Add the current directory to the directory list

DirectoryStructure ds = new DirectoryStructure();

ds.di = di;

int insertionIndex = 0;

// Let's get files in directory

foreach( FileInfo fi in di.GetFiles(fileFilter) )

{

fileList.Insert(insertionIndex, fi);

ds.fileList.Insert(insertionIndex, fi);

}

directoryList.Add(ds);

foreach( DirectoryInfo d in di.GetDirectories() )

{

RecursiveDirectoryNavigation( d );

}

}

catch {}

finally {}

}

WinXPDisableZeroConfigation.exe or WinXPDisableZeroConfigation

Well that's a long process name! Having just upgraded my network to a 11g network I found that my computers CPU usage was up from around the 3% mark it was now using about 55% some other people have reported much more cpu use than that!. What the heck was going on! I did the ctrl + alt + delete to bring up task manager scrolled down the list there was WinXPDisableZeroConfigation.exe hogging the CPU. I did a quick search on the internet some folk think its a trojan, spyware, adware. What I did find was its installed by the belkin software for the router or wireless card. It comes from software XpDis0Conf belonging to XPDisable0Conf. The file WinXPDisableZeroConfigation.exe can be found C:Program FilesBelkinBelkin 54Mbps Wireless UtilityTOOL if you accepted the default values when installing the belkin software. What I do based on info gained elsewhere is boot up and let WinXPDisableZeroConfigation run once your computer is up and running use task manager ( ctrl + alt + delete ) to end the process. I have not found any problems as yet.

To stop WinXPDisableZeroConfigation.exe from running at startup follow the instructions below. To do this you need to be an Administrator on the machine in question. Please read this first before you start. If this sounds too much for you use the above method using ctrl + alt + delete to end the process.

  • Click start, run
  • In the run box type msconfig and then click ok.
  • Click on the startup tab, should be the last tab on the right Uncheck winxpdisablezeroconfig.exe
  • Then click apply and then OK, reboot computer.
  • Reboot computer.
Using the process above will stop this process from running and should not cause any other problems." Having myself just done the above but without the reboot. All seemed OK. However I have just done a reboot. Once windows loads it gives a message saying You have used the System Configuration Utility to make changes to the way Windows starts. Etc Etc..... Basically put a tick in the tick box and the message will not show again unless you use the System Configuration Utility again for some reason. This is important. Some sypware malware hide up as WinXPDisableZeroConfigation.exe, the real size of WinXPDisableZeroConfigation is 32768 bytes To remove uninstall the Belkin utility and let Windows manage the wireless configuration don't uninstall the drivers for your card. Just let Windows XP do it stuff and you should be OK. Now you have read this read it again just to make sure you understand what you are about to do.

Whats your experiences of WinXPDisableZeroConfigation? Read other peoples experiences here http://www.searchhuts.co.uk/forum/topic.asp?TOPIC_ID=81

By John Hutchison

This articles can be found at John Hutchison site http://www.searchhuts.co.uk/portal/articles/activenews_view.asp?articleID=52