VB6 列出并删除目录中的所有文件
我需要获取目录中所有文件的名称,我当前正在使用此代码:
Dim File As String
File = Dir$(Environ("AppData") & "\*.exe")
Do While Len(File)
MsgBox "Deleting: " & Environ("AppData") & "\" & File
Kill Environ("AppData") & "\" & File
File = Dir$
Loop
这工作正常,但是它不显示隐藏/系统文件,或具有“正常”以外的任何属性的文件,我如何列出文件不管他们的属性如何?
我也尝试过,结果相同:
Kill Environ("AppData") & "\*.*"
I need to grab the names of all files in a directory, I am currently using this code:
Dim File As String
File = Dir$(Environ("AppData") & "\*.exe")
Do While Len(File)
MsgBox "Deleting: " & Environ("AppData") & "\" & File
Kill Environ("AppData") & "\" & File
File = Dir$
Loop
This works fine, however it does not display hidden/system files, or files with any attributes other than 'normal', how can I list files no matter their attributes?
I have tried this as well, which has the same outcome:
Kill Environ("AppData") & "\*.*"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Dir 函数可以采用第二个属性参数:
您可以找到有关 Dir 函数的更多信息 此处。
The Dir function can take a second parameter for attributes:
You can fin more about the Dir function here.
我几乎总是使用 Microsoft Scripting Runtime 从 VB6 进行文件 I/O。它只是做得更多,而且做得更好、更容易。一个微小的缺点是您的 VB 程序现在依赖于脚本运行时 DLL (
scrrun.dll
),您应该从 VB6 IDE 中将其添加为引用。以下是删除文件夹中所有文件的示例。
I pretty much always use the Microsoft Scripting Runtime for file I/O from VB6. It just does more, and it does it better and more easily. One tiny downside is that your VB program is now dependent on the Scripting Runtime DLL (
scrrun.dll
), which you should add as a reference from within the VB6 IDE.Here's an example that deletes all files from a folder.