File Search Program
Picture of File search program

This program was created for a number of reasons. I wanted to get to know C# and the .NET environment more, (I am a hands on type of person when it comes to learning). The other reason was that I had a project to remove a number of Crystal reports from all of our European servers, (there are 7 Servers that cover 19 countries). If it was just a case of removing the files then it might have been the case that just using windows search would have been enough. I had an extra complication that these files could be run manually or by automated processes setup over time. There is no central repository that lists these processes so it is a case of searching inside each file on the computer for the name of the reports I wanted to remove. This was not an appealing option!

The solution I came up with was to write a small program that would need the following information:

  • It would take in a list of files (these can be either the full or part of a name) to search for.
  • It would take in a list of file types to look for, this is to shrink the search to say just *.exe files
  • It would need folder location to act as a starting point for the search.
  • It would also need to where it would pipe its results to.
  • It would want to know what to do with the files it might find:
    • Nothing
    • Move them to a the output location, keeping the directory structure it presently has.
    • Delete the files.
  • It would also need to know what type of files it should look into to find references, i.e. INI, TXT, BAT or NONE

The process the program follows is as follows:

  • Set up search criteria.
  • It first checks to see if the directories and files given actually exist.
  • If so the files are loaded into memory
  • It then performs a recursive search for every file for can find and creates a list of these in memory, (files created and used by the program are removed to avoid circular references)
  • This list is then searched for the files needed and if they required it searches inside each file to find any references to the reports wanted.
  • The files are processed and dealt with accordingly (moved, deleted or nothing)
  • Finally a text file report is produced to show what has been found.

This has and still is proving to be a useful tool as we replace all of our crystal reports (some 150+ of them) and removing them and all their references from our servers.

If you would like to have a copy of the program or the code please download the zip from here

I Hope you found this interesting and may even find a use for this program your self. My development in C# has improved some what since creating this application but it does work well and I am pleased with the result.

FAQ

  • Can not get the program to run?
  • .NET applications can not be run from a network drive (mapped or access a network) unless you have set up the correct permissions. To resolve this try running it from your C drive or another physical drive on that computer.
  • Seems to be running very slowly!
  • It might be the case that there is just a large amount to search. Depending on how busy some of the servers were at the time it could take an hour or two to run over 100GB or so. Saying that on our newer servers it would do the same work in ten or so minutes. A reason it could be running slowly is if you are trying to search a remote computer. I would STRONGLY recommend only running this on the computer you wish to search. The network will add a lot of time to the process.
  • It keeps crashing!
  • The program tries to write an error log when ever it runs into a program it can or can not deal with. This should be in the same location as the output folder.