如何使用FileSystem.GetFiles并忽略回收站? [英] How do I use FileSystem.GetFiles and ignore Recycle Bin?

查看:96
本文介绍了如何使用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))
    
   Next

End Sub

推荐答案

是的,有一个选项可以排除系统r隐藏文件。使用 if ...... then [ ^ ]语句中的每个循环。< br $> b $ b

Yes, there is an option to exclude system r hidden files. Use if ... then[^] statement inside for each loop.

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[^]


首先,我不推荐任何VB。 NET相关。为什么不使用纯.NET BCL: http://msdn.microsoft。 com / zh-CN / library / ms143316%28v = vs.110%29.aspx [ ^ ]?



然而,你什么都得不到新。这些类型和方法清楚地表明......您不能忽略搜索中的某个特定目录。在进一步处理中,您需要找到所有文件,然后忽略一些找到的文件。



-SA
First of all, I would not recommend anything VB.NET-related. Why not using pure .NET BCL: http://msdn.microsoft.com/en-us/library/ms143316%28v=vs.110%29.aspx[^]?

However, you won't get anything new. Those types and methods clearly show… that you cannot ignore some particular directory from the search. You will need to find all files and then ignore some of the found ones, in further processing.

—SA


非常感谢,自从我使用VB以来,这是一个漫长的时间,它现在已经100%不同了。
Thanks very much, its been a loooong time since I used VB, it's 100% different now.


这篇关于如何使用FileSystem.GetFiles并忽略回收站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆