By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

List folder names on c:\

P: 25
Hi,

I'm using access 2003. Could someone help me list just the folder name on c:\access\ and save it into a table. Right now when I use vbdirectory, it list all my sub folders as well as the files that are in c:\access\. I just need list of the folder names. for example, on my c:\access\ I have access97 and access03 folders and also I have access.mdb file. On the table, I just want it to say access 97 on one row and access03 on the other row.
Could someone please help me?

Thank you in advance.
Jul 29 '09 #1
Share this Question
Share on Google+
5 Replies


Expert 100+
P: 634
@Bay0519
Hi

May be you could try this (air code),
Expand|Select|Wrap|Line Numbers
  1. Sub InsertDirectories()
  2.     Dim DirectoryName
  3.     Dim sql
  4.  
  5.     DirectoryName = Dir("C:\Access\", vbDirectory)
  6.     Do Until DirectoryName = ""
  7.         If DirectoryName <> "." And DirectoryName <> ".." Then
  8.  
  9.             sql = "INSERT INTO YourTable ( YourField ) " & _
  10.                 "SELECT '" & DirectoryName & "' AS Directory"
  11.  
  12.             CurrentProject.Connection.Execute sql
  13.         End If
  14.         DirectoryName = Dir
  15.     Loop
  16. End Sub
I think this should do what you want. If you want to save the full path to these directories then "C:\Access\" will need adding to the DirectoryName.

MTB
Jul 30 '09 #2

P: 25
Hi Mike,

Thank you for the reply and it's still showing all the files inside the c:\access\. I just want to display the subfolders inside the c:\access\ which is access03 and access97 without the access.mdb files.
Could you please help??

Thank you in advance.
Jul 30 '09 #3

Expert 100+
P: 634
@Bay0519
Sorry missed a bit out, try this
Expand|Select|Wrap|Line Numbers
  1. Sub InsertDirectories()
  2.     Dim DirectoryName
  3.     Dim sql
  4.     Dim Folder As String
  5.  
  6.     Folder = "C:\Access\"
  7.  
  8.     DirectoryName = Dir(Folder, vbDirectory)
  9.     Do Until DirectoryName = ""
  10.         If DirectoryName <> "." And DirectoryName <> ".." Then
  11.             If (GetAttr(Folder & DirectoryName) And vbDirectory) = vbDirectory Then
  12.  
  13.             sql = "INSERT INTO YourTable ( YourField ) " & _
  14.                 "SELECT '" & DirectoryName & "' AS Directory"
  15.  
  16.             CurrentProject.Connection.Execute sql
  17.  
  18.             End If
  19.         End If
  20.         DirectoryName = Dir
  21.     Loop
  22. End Sub
I think all this is in VB Help

MTB
Jul 31 '09 #4

P: 25
It worked!!! Thank you so much Mike. I really really appreciate it...
Jul 31 '09 #5

NeoPa
Expert Mod 15k+
P: 31,489
I've moved this thread to the Answers forum (from Insights).

Please be careful in future to use the correct forum for your threads :
Answers = Questions requiring help.
Insights = An article providing help or information.
Aug 9 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.