Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 DirectoryInfo Methods

Author  Topic 

tecknowledge1164
Starting Member

25 Posts

Posted - 2007-09-21 : 12:30:08
I am writing a sub in vb.net to find files in a specified location, copy them to another location and add some information about them to the database. Usually the files are all in one folder so once I point to it I can declare a DirectoryInfo then loop through the files to do the operation. It looks something like this:

Dim d as New IO.DirectoryInfo(sSourcePath)

For Each f As IO.FileInfo in d.GetFiles
copy file
do some other stuff
Next

Now I have a situation where the files are all located in subfolders inside of one main folder. It looks like to get at them using the main folder as my sSourcePath I am going to have to include the GetDirectories method of the DirectoryInfo class. I am not having much luck getting the code to work with this. Basically all I need to do is search all the subfolders in the main folder and work with the files. If anyone could give me an idea of how that syntax would compare to what I have here I would appreciate it. Thanks in advance.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-09-21 : 14:45:03
Directory.GetFiles(sSourcePath, "*.*", SearchOption.AllDirectories)

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

tecknowledge1164
Starting Member

25 Posts

Posted - 2007-10-03 : 12:10:12
Sorry it took so long to respond to this. That worked perfectly, thanks.
Go to Top of Page
   

- Advertisement -