You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB.NET中Directory.EnumerateFiles如何获取隐藏文件?

如何用Directory.EnumerateFiles获取隐藏文件

Directory.EnumerateFiles 完全可以获取隐藏文件,你当前没拿到的原因是EnumerationOptions的默认规则会跳过隐藏项,只需调整配置即可解决。

默认情况下,EnumerationOptions的AttributesToSkip属性自带FileAttributes.Hidden和FileAttributes.System筛选,会自动排除隐藏文件。你需要显式修改这个属性,让它不跳过隐藏文件:

修改后的代码如下:

For Each mFile In Directory.EnumerateFiles("g:\trash\test"
   , "*", New IO.EnumerationOptions 
With {
 .IgnoreInaccessible = True
 , .RecurseSubdirectories = True
 , .ReturnSpecialDirectories = True
 , .AttributesToSkip = FileAttributes.None ' 关键修改:不跳过任何属性的文件
})

如果你的需求是只排除特定属性(比如只跳过系统文件,保留隐藏文件),可以把AttributesToSkip设为对应的值,比如:

.AttributesToSkip = FileAttributes.System

内容的提问来源于stack exchange,提问作者jvcoach23

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 04:45:54