Read files in subdirectories

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hello,

I want to make a command line application that search for *.htm* files
inside directories and subdirectories.

1.
How can I save all the *.htm* files inside directories and subdirectories
inside a array?
Can you give me an example?

2.
I want to search inside these files. And if found... replace some text and
save the file under the same name.
Can you give me an example?

Thanks!
Arjen
 
Arjen,

You can easily do this using the File and Directory classes in the
System.IO namespace. Basically, you can use the static GetDirectories
method on the Directory class to get sub directories. Then, you can use the
GetFiles method to get the files in each directory. Scanning through all of
the content using these methods should be a trivial process.

Also, you might want to consider using the Win32 API and calling the
FindFirstFile functions through the P/Invoke layer. They could be much much
faster for what you want to do.

Hope this helps.
 
Nicholas said:
Arjen,

You can easily do this using the File and Directory classes in the
System.IO namespace. Basically, you can use the static GetDirectories
method on the Directory class to get sub directories. Then, you can
use the GetFiles method to get the files in each directory. Scanning
through all of the content using these methods should be a trivial
process.

Also, you might want to consider using the Win32 API and calling
the FindFirstFile functions through the P/Invoke layer. They could
be much much faster for what you want to do.

Hope this helps.

The win32 API also give the right answer. I have found the CLR one to
give incorrect sizing information for files on CD's where compression
may be involved.
 
Back
Top