以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  如何不处理隐藏和系统文件?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=56115)

--  作者:wh420
--  发布时间:2014/8/29 16:26:00
--  如何不处理隐藏和系统文件?
以下代码定义成函数,功能是提取给定目录的所有文件名称:
Dim path As String = args(0)
Dim box As object = args(1)

For Each file As String In FileSys.GetFiles(path)
    If box.value > "" Then
        box.value &= vbcrlf & FileSys.GetName(file)
    Else
        box.value &= FileSys.GetName(file)
    End If
Next

For Each p As String In FileSys.GetDirectories(path)
    Functions.Execute("递归", p, box)
Next

——————————————————
我在一个窗口的按钮调用

Functions.Execute("递归", txt.value, e.Form.Controls("TextBox1"))

问题:可以正常提取目录下的所有文件名,但目录中隐藏的和系统文件也提出来了,我不需要这些隐藏的和系统的文件,如何解决?

--  作者:有点甜
--  发布时间:2014/8/29 16:28:00
--  

 你可以去判断文件的属性,从而确定是否需要显示出来

 

http://www.foxtable.com/help/topics/2707.htm

 


--  作者:wh420
--  发布时间:2014/8/29 17:37:00
--  
这个我看过,但还是不太明白。麻烦您加到我上面的代码中,谢谢
--  作者:有点甜
--  发布时间:2014/8/29 17:44:00
--  

Dim path As String = args(0)
Dim box As object = args(1)


For Each file As String In FileSys.GetFiles(path)
    Dim ifo As new FileInfo(file)
    If ifo.Hidden = False Then
        If box.value > "" Then
            box.value &= vbcrlf & FileSys.GetName(file)
        Else
            box.value &= FileSys.GetName(file)
        End If
    End If
Next


For Each p As String In FileSys.GetDirectories(path)
    Functions.Execute("递归", p, box)
Next