Need on subfolders that are numbers

B

brad7100

I have the following code which puts the names of all subfolders in a
folder into a table. But, I want to limit it to only subfolders that
have a name that is numbers because most subfolders are named 1000,
1001, etc. but some subfolders in this folder have a name like
"archives", I only want the numbered folders - How can I limit it to
only the number folders, what code should be added.:

Dim fso As Object, objfolder As Object
Dim fld As Object, fyl As Object
Dim n As Integer
Set fso = CreateObject("Scripting.FileSystemObject")
Dim cmd As ADODB.command
Dim strSQL As String
Dim strFile As String
Dim strFullPath As String

Set cmd = New ADODB.command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

' wipe the table
strSQL = "DELETE * FROM tblSubFolders"
cmd.CommandText = strSQL
cmd.Execute

' set your parent folder here that you want subfolders from
Set objfolder = fso.GetFolder("d:\apps\database documents")

' fill tblSubFolders with the folder names and created date
If objfolder.Subfolders.Count Then
For Each fld In objfolder.Subfolders
lDirNum = lDirNum + 1

strSQL = "INSERT INTO tblSubFolders(FolderName,
CreatedDateTime) VALUES (" & _
Chr(34) & fld.Name & Chr(34) & "," & Chr(34) &
fld.DateCreated & Chr(34) & ")"

cmd.CommandText = strSQL
cmd.Execute
Next fld
End If

Set cmd = Nothing
Set fld = Nothing
Set objfolder = Nothing
Set fso = Nothing
 
P

Pieter Wijnen

change to:

If IsNumeric(FolderName) Then cmd.Execute


HtH

Pieter

I have the following code which puts the names of all subfolders in a
folder into a table. But, I want to limit it to only subfolders that
have a name that is numbers because most subfolders are named 1000,
1001, etc. but some subfolders in this folder have a name like
"archives", I only want the numbered folders - How can I limit it to
only the number folders, what code should be added.:

Dim fso As Object, objfolder As Object
Dim fld As Object, fyl As Object
Dim n As Integer
Set fso = CreateObject("Scripting.FileSystemObject")
Dim cmd As ADODB.command
Dim strSQL As String
Dim strFile As String
Dim strFullPath As String

Set cmd = New ADODB.command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

' wipe the table
strSQL = "DELETE * FROM tblSubFolders"
cmd.CommandText = strSQL
cmd.Execute

' set your parent folder here that you want subfolders from
Set objfolder = fso.GetFolder("d:\apps\database documents")

' fill tblSubFolders with the folder names and created date
If objfolder.Subfolders.Count Then
For Each fld In objfolder.Subfolders
lDirNum = lDirNum + 1

strSQL = "INSERT INTO tblSubFolders(FolderName,
CreatedDateTime) VALUES (" & _
Chr(34) & fld.Name & Chr(34) & "," & Chr(34) &
fld.DateCreated & Chr(34) & ")"

cmd.CommandText = strSQL
'Here
If IsNumeric(FolderName) Then cmd.Execute
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top