eyeball Posted September 25, 2007 Posted September 25, 2007 (edited) Hi all,i have been working on a small program that scans a directory and does the following1) creates a table in an access database by the same name as each subdirectory of the path2)eventually it will populate these tables with the files contained in the db, but thats were i need some helpsee code below Dim con As New OleDb.OleDbConnection 'create variable called con that connects to a DB 'Dim ds As New DataSet 'create a variable called ds that is the dataset Dim VarAddTable As String 'Create Variable called VarAddTable Dim VarAddRecord As String con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = c:\Videos.mdb" 'use the con variable to connect to a database file con.Open() 'open a connection to the database 'scan first directory For Each folder As String In IO.Directory.GetDirectories(txtdirectory1.Text) VarAddTable = IO.Path.GetFileName(folder) Dim objCommand As New System.Data.OleDb.OleDbCommand("CREATE TABLE [" & VarAddTable & "] (field1 Text(25) null, field2 long not null)", con) objCommand.ExecuteNonQuery() 'execute the objcommand Variable 'scan within each directory For Each FileName As String In System.IO.Directory.GetFiles(folder, FileIO.SearchOption.SearchAllSubDirectories, "*.avi") VarAddRecord = System.IO.Path.GetFileNameWithoutExtension(FileName) MsgBox(" the file name is" & VarAddRecord) Next FileName Next folder 'end of scanning dirs and files con.Close() MsgBox("the connection is closed and your tables should have been created") End SubEnd Classi know it doesnt work but thats why i left it like that, i hope you can see how im thinking from this.the FileIO.searchallsubdirectories part doesnt work, but as you can see i need to be able to search the path in folder for *.avi so i can then move on to doing something with it.for now though any subfiles it finds are just shown in a message boxcan anyone help please? thank you Edited September 25, 2007 by eyeball
eyeball Posted September 26, 2007 Author Posted September 26, 2007 its ok i got it, someone told me (and i quote)"The Directory.GetFiles() method has an overload that can accept a filter expression."so therefore the line of code i needed was simplyFor Each FileName As String In System.IO.Directory.GetFiles(folder, "*.avi")
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now