Need on subfolders that are numbers

  • Thread starter Thread starter brad7100
  • Start date Start date
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
 
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
 
Back
Top