Find number of files

G

Guest

I have a tiny db that imports a txt file, deletes some rows, does some
calculations, deletes the file and then prints out a report. (quick
explanation)

To make sure there is only one file imported, and also the correct one, I
force the user to cut and paste from one folder to another before clicking
the button that imports, does all the stuff and finally print and close
Access.

Is there any way to check how many files there are in a specific folder?
File name blabla*.txt

Then I could run the code only if there is only one file in the folder.
(matching above criteria.)
Note that there are alot of files in the folder, but they are named
differently.
Otherwise show a message saying that there are multiple files or something.

Greatful for any code I can use for this.

BR
Claes
 
J

John Nurick

Hi Claes,

This snippet shows one way:


Dim Folder As String
Dim FileSpec As String
Dim FileToImport As String

Folder = "D:\Folder\Subfolder"
FileSpec = "blabla*.txt"

FileToImport = Dir(Folder & "\" & FileSpec)

If Len(FileToImport) = 0 Then
'No files fit FileSpc

Else
'One file fits FileSpec
'Call Dir() again to see if there's another
If Len(Dir) = 0 Then
'The file we've got is the only one
'Import Folder & "\" & FileToImport
...
Else
'There are at least two files in
'Folder that match FileSpec
...
End If
End If
 

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