andriscs

Hi,

I'm developing a program that deletes data in a specified directory. I'd like to know how much data is deleted so my program has to determine the directory size before delete and after it. As I've read it, no "built-in" method exists to get the size of a directory, only recursive way is available because of the nature of directory type.
The problem is that I have a directory with lots of files in it. If I liked to get its size, it takes very long time. Because the data will be deleted, I can't let it happen that the directory size is determined in an asynchronous way while the program continues its run and deletes the data because it causes inconsistency. I could make the size determination run asynchronously and after it is done then let the delete begin. It would work, I guess but takes long time and during size calculation no useful function can be run. Any idea for a better and more effective way




Re: Visual C# General Directory size question

Rollercoaster


Well, there is no software way to increase the HDDs transfers or to determine the contents of a directory without parsing its contents.

The only conceptual method would be to create some kind of background service that monitors the directories that are concerned with ur app or use the indexing service, if possible, for your benefit.





Re: Visual C# General Directory size question

andriscs

I've never done anything like that before. By using indexing service you mean Windows' indexing service that is used to accelerate search in directories How can I use it





Re: Visual C# General Directory size question

Rollercoaster

see this for a pointer for example then u can go on and search the world wide web for more specific stuff
http://www.codeproject.com/useritems/Indexing_Service_HOW-TO.asp





Re: Visual C# General Directory size question

andriscs

Okay, I solved it with sort of a workaround.

Instead of determining directory size I collect the drives that contain the directories and check the sum of available free space of drives before delete and after it. It is significally faster than the previous method though it probably needs more resources because of the usage of ManagementObejcts and could be less accurate considering that other programs might delete data as well during run.





Re: Visual C# General Directory size question

sirjis

Well, if it's your program that's doing the deleting, can't you just keep track of how much you've deleted as you delete it Or is something more complicated going on




Re: Visual C# General Directory size question

andriscs

Nothing too complex, I simply use Directory.Delete(dir,true) and File.Delete(file). Unfortunately these methods do not provide information about how much data was deleted. I don't know about any other way to delete, if you have idea, I'd appreciate it.