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

Code To Check a Folder For any Files

P: n/a
Access 2000

I need to check a particular folder for files of a particular type
(such as *.txt) Prior to the next step. If Files of said type are
present, then the code will continue, else it would stop & give the
user a warning & exit.

The file check is the part I am having trouble with, I don't know
where to start.

Any & ALL help truly appreciated!

Dale
Nov 13 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Dale Ring wrote:
Access 2000

I need to check a particular folder for files of a particular type
(such as *.txt) Prior to the next step. If Files of said type are
present, then the code will continue, else it would stop & give the
user a warning & exit.

The file check is the part I am having trouble with, I don't know
where to start.

Any & ALL help truly appreciated!

Dale


Check out the Dir() function. Something like this:

Public Sub processFolder(sPath As String)
Dim sFileName As String, nID As Long

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.txt", vbNormal)
Do While Len(sFileName) & vbNullString > 0
'<do some processing here>
sFileName = Dir()
Loop

End If

End Sub

--
'-------------------------------
' John Mishefske
'-------------------------------

Nov 13 '05 #2

P: n/a
There may be several files of several different types in the folder.

All I want to know is: Is the folder empty? Yes or No

From that point I can decide what I want the code to do next.

Dale

John Mishefske <mi****@execpc.com> wrote in message news:<10*************@corp.supernews.com>...
Dale Ring wrote:
Access 2000

I need to check a particular folder for files of a particular type
(such as *.txt) Prior to the next step. If Files of said type are
present, then the code will continue, else it would stop & give the
user a warning & exit.

The file check is the part I am having trouble with, I don't know
where to start.

Any & ALL help truly appreciated!

Dale


Check out the Dir() function. Something like this:

Public Sub processFolder(sPath As String)
Dim sFileName As String, nID As Long

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.txt", vbNormal)
Do While Len(sFileName) & vbNullString > 0
'<do some processing here>
sFileName = Dir()
Loop

End If

End Sub

Nov 13 '05 #3

P: n/a
mt****@yadtel.net (Dale Ring) wrote in message news:<d5*************************@posting.google.c om>...
There may be several files of several different types in the folder.

All I want to know is: Is the folder empty? Yes or No


<SNIP>
Check out the Dir() function. Something like this:

Public Sub processFolder(sPath As String)
Dim sFileName As String, nID As Long

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.txt", vbNormal)
Do While Len(sFileName) & vbNullString > 0
'<do some processing here>
sFileName = Dir()
Loop

End If

End Sub

So make the sub a function.

This worked for me... your mileage may vary. You'll need the
BrowseFolder API from www.mpvs.org from the API section.

Option Compare Database
Option Explicit

Private Sub Command0_Click()
Dim sPath As String

sPath = BrowseFolder("What Folder you want to select?")
Me.txtFolder = sPath

MsgBox "Path: " & sPath & " empty: " & IsEmptyFolder(sPath)
End Sub

Public Function IsEmptyFolder(ByVal sPath As String) As Boolean
Dim sFileName As String, nID As Long

IsEmptyFolder = True

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.*", vbNormal)
IsEmptyFolder = (Len(sFileName) & vbNullString = 0)
End If
End Function
Nov 13 '05 #4

P: n/a
mt****@yadtel.net (Dale Ring) wrote in message news:<d5*************************@posting.google.c om>...
There may be several files of several different types in the folder.

All I want to know is: Is the folder empty? Yes or No


<SNIP>
Check out the Dir() function. Something like this:

Public Sub processFolder(sPath As String)
Dim sFileName As String, nID As Long

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.txt", vbNormal)
Do While Len(sFileName) & vbNullString > 0
'<do some processing here>
sFileName = Dir()
Loop

End If

End Sub

So make the sub a function.

This worked for me... your mileage may vary. You'll need the
BrowseFolder API from www.mpvs.org from the API section.

Option Compare Database
Option Explicit

Private Sub Command0_Click()
Dim sPath As String

sPath = BrowseFolder("What Folder you want to select?")
Me.txtFolder = sPath

MsgBox "Path: " & sPath & " empty: " & IsEmptyFolder(sPath)
End Sub

Public Function IsEmptyFolder(ByVal sPath As String) As Boolean
Dim sFileName As String, nID As Long

IsEmptyFolder = True

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.*", vbNormal)
IsEmptyFolder = (Len(sFileName) & vbNullString = 0)
End If
End Function
Nov 13 '05 #5

P: n/a
mt****@yadtel.net (Dale Ring) wrote in message news:<d5*************************@posting.google.c om>...
There may be several files of several different types in the folder.

All I want to know is: Is the folder empty? Yes or No


<SNIP>
Check out the Dir() function. Something like this:

Public Sub processFolder(sPath As String)
Dim sFileName As String, nID As Long

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.txt", vbNormal)
Do While Len(sFileName) & vbNullString > 0
'<do some processing here>
sFileName = Dir()
Loop

End If

End Sub

So make the sub a function.

This worked for me... your mileage may vary. You'll need the
BrowseFolder API from www.mpvs.org from the API section.

Option Compare Database
Option Explicit

Private Sub Command0_Click()
Dim sPath As String

sPath = BrowseFolder("What Folder you want to select?")
Me.txtFolder = sPath

MsgBox "Path: " & sPath & " empty: " & IsEmptyFolder(sPath)
End Sub

Public Function IsEmptyFolder(ByVal sPath As String) As Boolean
Dim sFileName As String, nID As Long

IsEmptyFolder = True

If Len(Dir(sPath, vbDirectory)) & vbNullString > 0 Then
sFileName = Dir(sPath & "\*.*", vbNormal)
IsEmptyFolder = (Len(sFileName) & vbNullString = 0)
End If
End Function
Nov 13 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.