本文介绍了如何使用FileSystem.GetFiles并忽略回收站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 问候。 我好几年没用VB了,所以这就像从头学习一样。 我正在摆弄:My.Computer.FileSystem.GetFiles程序,除非我选择包含系统文件夹(如回收站或应用程序数据)的路径,否则它的效果很好。 调用GetFiles过程时发生异常几天我会在磁盘上找到它后测试每个文件的属性。我认为可以选择排除系统或隐藏文件。 这是一个非常非常简单的例子: Greetings. I haven't used VB in several years, so this is like learning from scratch again.I'm fiddling around with: My.Computer.FileSystem.GetFiles procedure, it works well except when I select a path including system folders like the Recycle Bin or Application Data.The exception happens when the GetFiles procedure is called, in the old days I would have tested the attributes of each file after finding it on disk. I would think that there would be an option to exclude System or hidden files.Here is a very, very simple example:Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click For Each foundFile As String In My.Computer.FileSystem.GetFiles _ (txtDIR.Text, _ FileIO.SearchOption.SearchAllSubDirectories, "*") Dim attributes As FileAttributes attributes = File.GetAttributes(foundFile) List2.Items.Add(IO.Path.GetFileName(foundFile)) NextEnd Sub 推荐答案 Dim attributes = File.GetAttributes(foundFile) If ((attributes And FileAttributes.ReadOnly) <> FileAttributes.ReadOnly) Then 'add to list 更多信息请参阅: 演练:在Visual Basic中操作文件和目录 [ ^ ] 如何:枚举目录和文件 [ ^ ] FileAttributes Enumeration [ ^ ] For further information please see:Walkthrough: Manipulating Files and Directories in Visual Basic[^]How to: Enumerate Directories and Files[^]FileAttributes Enumeration[^] 这篇关于如何使用FileSystem.GetFiles并忽略回收站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 16:32