1

我一直在到处寻找可以不断检查目录以查看是否有任何新文件的东西,如果有,它将将该文件名添加到列表中

我有这个,但只有当我点击列表时它才有效

   Dim JAR As String = "*.jpg"
    Dim DirInfo As DirectoryInfo = New DirectoryInfo(dir)
    Dim Files() As FileInfo = DirInfo.GetFiles(JAR, SearchOption.AllDirectories)
    Dim File As FileInfo
    Const extension As String = ".jpg"
    For Each File In Files
        If (Not list.Items.Contains(File.Name)) Then
            list.Items.Add(File.Name)
            list.Text.Substring(0, ClientList.Text.Length - extension.Length)
            list.Text = list.Items.Count
        End If
    Next (File)
4

2 回答 2

3

我认为您正在寻找FileSystemWatcher Class

侦听文件系统更改通知并在目录或目录中的文件更改时引发事件。

于 2013-05-24T20:06:08.960 回答
0

一个简单的解决方案是检查该文件是否是今天创建的。

    Dim files As FileSystemInfo
    Dim path As String
    path = "C:\myDirectory\"

    Dim childinfo As New DirectoryInfo(path)

        For Each files As FileSystemInfo In childinfo.GetFileSystemInfos()

            ' Select only files within the day (format: MM/DD/YY)
            ' It does not include old files being kept in the folder

            If files.CreationTime.Date.Equals(Date.Today) Then
                list.Add(path & files.Name)
            End If

        Next

但是查看 FileSystemWatcher 类将是一个不错的选择。

于 2013-05-31T00:23:08.983 回答