Click here to Skip to main content
15,891,646 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I am looking to use Visual Studio C# Express to create a simple program that will look through all files/folders on all logical drives (with an option to do this for mounted network drives if possible). I need extensive information about the files including as much metadata as possible, fullpath, file extension, and file signature if possible.

This point of this program is to hand it to a client on a thumb drive and they can give us back an encrypted file of essentially a "snapshot" of their directory structure/etc which we can play with later. It's fairly important this program has some integrity in the sense if it crashes or fails at any point.

I was planning on using this code as a base:

http://msdn.microsoft.com/en-us/library/bb513869.aspx[^]

It looked like .NET 4 had more sophisticated ways of doing this, but the constraints are limited to older machines that may not have XP SP3.

1. What is the best method of also iterating through mounted network drives? Is it even possible?

2. Is this above code the "best choice" to iterate through the entire computer? I'm going to need to pull aforementioned data about each file and export it into XML or Access.

3. Given the possible size of the data, what is the best practice for storing this mass of information for export later into XML/db/etc?

4. What are the best practices for handling encrypting a file after we're done writing to it?
Posted
Updated 28-Oct-10 9:23am
v3
Comments
Nish Nishant 28-Oct-10 14:54pm    
Your link does not work. Can you fix it?

It points to http://msdn.microsoft.com/en-us/library/bb513869.asp right now.
Nish Nishant 28-Oct-10 15:22pm    
Ok, it was a missing x, the right URL is :
http://msdn.microsoft.com/en-us/library/bb513869.aspx
Nish Nishant 28-Oct-10 15:24pm    
Okay, I edited your post and fixed the link.

1) Yes, you can iterate network drives as well. You may have to use WMI to get the shares, but it should be possible.

2) I don't know if the best or not, because I've never wanted to do anything like this.

3) I would use linq to write it to a xml file

4) Just, ummm, encrypt it.

Your request for "best practice" will result in nothing but you chasing what everyone else's idea of "best practice" is. Use google to see how everyone eklse is doing it, and then pick the way that you feel most comfortable with.
 
Share this answer
 
If performance is your primary concern, you are already doing it fairly well - since the code in the article partitions the files/directory enumeration (instead of recursively starting at the root with a single call).

Since the memory needed to hold a fairly large array of file-information would be pretty big, it would probably be a good idea to partition the file-writes too (whether it's XML or some other data format). That way you don't need to keep everything in memory

And as for encryption, use one of the crypto classes provided with the framework. You can choose to wait for the entire process to finish and then encrypt the big file in one go. Or you could encrypt and write during each of the partitioned writes. That's up to you.

You may also want to keep some sort of current index/position so that if you crash or the app has to be temporarily terminated, you need not start from the beginning and can resume from where you left off.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900