MS-Access 嵌套 DIR - 在循环访问文件夹时检查文件是否存在于其他位置

发布于 2024-08-30 10:24:42 字数 361 浏览 9 评论 0原文

我在 Microsoft Access 2003 中使用了 DIR() 命令来循环访问文件夹 A 中的文件。这工作正常,但我需要检查每个文件是否也存在于另一个位置(文件夹 B)中,并且仅在存在时才处理该文件文件夹 B 中不存在。

问题是,检查文件夹 B 中存在的文件也使用了 DIR() 函数,然后这会重置或混淆原始文件,结果是在文件夹 A 中找不到更多文件。

有没有一种方法可以在不使用 DIR 的情况下检查文件是否存在?

或者,有没有办法拥有一个单独的 DIR 实例?

我想我可以将文件夹 A 中的文件列表构建到一个数组中,然后处理数组中的条目,但这看起来相当“笨拙”

对于更好的解决方案有什么建议吗?

谢谢

I have used the DIR() command in Microsoft Access 2003 to loop through the files in folder A. This works fine, but I need to check if each file also exists in another location (folder B), and only process the file if it doesn't exist in folder B.

The problem is that checking for the file existing in folder B also uses the DIR() function and this then resets or confuses the original one, with the result that no further files are found in folder A.

Is there a way to check if a file exists without using DIR?

Or, is there a way to have a separate instance of DIR?

I suppose I could build a list of the files in folder A into an array and then process the entries in the array, but this seems rather 'clunky'

Any suggestions for a better solution?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

勿忘心安 2024-09-06 10:24:42

根据您的操作系统和要求,您可能会发现搜索 SystemIndex 很有用。这里有一些注意事项。

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String

''This is the Windows Search connection string to use
cn.Open "Provider=Search.CollatorDSO;" _
    & "Extended Properties='Application=Windows';"

''SQL SELECT  statement specifies what properties to return,
''            you can add more if you want
''    FROM -  use SystemIndex for a local query or
''            MACHINENAME.SystemIndex for remote
''    WHERE - specify restrictions including SCOPE and other
''            conditions that must be true

''To add scope restriction:
''strSQL = "SELECT System.ItemName, System.ItemTypeText, " _
''       & "System.Size FROM SystemIndex " _
''       & "WHERE Scope='file:c:\Users\'"

strSQL = "SELECT System.ItemName, System.ItemTypeText, " _
       & "System.Size, System.ItemFolderPathDisplay " _
       & "FROM SystemIndex " _
       & "WHERE System.ItemName='AnExampleFile.mdb'"

rs.Open strSQL, cn
rs.MoveFirst

Do Until rs.EOF
    Debug.Print rs.Fields.Item("System.ItemName")
    Debug.Print rs.Fields.Item("System.ItemTypeText")
    Debug.Print rs.Fields.Item("System.Size")
    Debug.Print rs.Fields.Item("System.ItemFolderPathDisplay")
    Debug.Print String(30, "-")
    rs.MoveNext
Loop

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

更多信息:
http://msdn.microsoft.com/en-us /library/bb266517(VS.85).aspx
http://msdn.microsoft.com/en -us/library/bb419046(v=VS.85).aspx
http://msdn.microsoft.com/en -us/library/bb776859(v=VS.85).aspx
http://msdn.microsoft.com/en -us/library/bb231297(v=VS.85).aspx

Depending on your operating system(s) and requirements, you may find searching the SystemIndex useful. Here are some notes.

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSQL As String

''This is the Windows Search connection string to use
cn.Open "Provider=Search.CollatorDSO;" _
    & "Extended Properties='Application=Windows';"

''SQL SELECT  statement specifies what properties to return,
''            you can add more if you want
''    FROM -  use SystemIndex for a local query or
''            MACHINENAME.SystemIndex for remote
''    WHERE - specify restrictions including SCOPE and other
''            conditions that must be true

''To add scope restriction:
''strSQL = "SELECT System.ItemName, System.ItemTypeText, " _
''       & "System.Size FROM SystemIndex " _
''       & "WHERE Scope='file:c:\Users\'"

strSQL = "SELECT System.ItemName, System.ItemTypeText, " _
       & "System.Size, System.ItemFolderPathDisplay " _
       & "FROM SystemIndex " _
       & "WHERE System.ItemName='AnExampleFile.mdb'"

rs.Open strSQL, cn
rs.MoveFirst

Do Until rs.EOF
    Debug.Print rs.Fields.Item("System.ItemName")
    Debug.Print rs.Fields.Item("System.ItemTypeText")
    Debug.Print rs.Fields.Item("System.Size")
    Debug.Print rs.Fields.Item("System.ItemFolderPathDisplay")
    Debug.Print String(30, "-")
    rs.MoveNext
Loop

rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing

Further Information:
http://msdn.microsoft.com/en-us/library/bb266517(VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb419046(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb776859(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/bb231297(v=VS.85).aspx

月隐月明月朦胧 2024-09-06 10:24:42

我更喜欢文件 API,因为我不太信任 FSO。另请参阅 FindFirstFile:性能比较 - FSO 与 API少于一百个文件,性能差异并不那么显着。许多示例代码对于直接文件列表或递归子文件夹非常有用,位于 文件 API 例程

I prefer the file APIs as I don't quite trust the FSO. Also see FindFirstFile: Performance Comparison - FSO vs. API With less than say a hundred files the performance difference isn't that significant. Lots of sample code that will be useful for a straight file list or recursively thorugh sub folders at File API Routines

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文