循环遍历目录中的所有数据库
问题描述:
我需要遍历某个目录中的所有数据库,其中数据库名称为ACPwxyz.mdb
,其中wxyz等同于数据库所用期间的MMYY值。循环遍历目录中的所有数据库
例如,2017年7月的数据库将为ACP0717.mdb。
我从来没有写过VB6之前,我完全恨它,但它是一个现有项目的扩展,所以我坚持下去!
有没有办法循环目录中的所有文件,检查文件名是否遵循ACPwxyz.mdb
的格式,如果是,那么打开一个连接?
我环顾了一下,看到Dir(x, y)
,但我不确定在这种情况下我是否可以使用它?
任何提示将不胜感激。
答
您可以使用Dir
,是的。
如果使用这样的事情:
Dim strFile As String
strFile = Dir(yourDBPath, "ACP????.mdb") ' mdb for MS-Access files
Do Until strFile = ""
If Len(strFile) = 11 Then ' Ensure the DB file name is 11 characters, which yours are
'Do something // You can also check the file name doesn't = a certain name if needed
End If
strFile = Dir
Loop
Dir
可以接受星号(*)或问号作为文件名中的通配符,所以这将寻找任何数据库中集(?)名为ACP
的路径后跟4个字符。
雇用一个VB6程序员。 – Bob77
同意@ Bob77。 –