我有一个文件,我们称之为“myFile.txt”,在一个文件夹中。在同一文件夹中还会有其他名为“myFile1.txt,myFile2.txt,myFile3.txt,myFile4.txt”的文件,依此类推。我想检查该文件夹并计算“myFile”在该文件夹中显示的次数,无论扩展名或“myFile”之后的数字。这是我到目前为止所拥有的,但它没有得到我想要的东西:
$("input[type='checkbox']:checked").prop("checked", true)
答案 0 :(得分:1)
我掀起了这个并在Visual Studio中测试过它:
'Get a list of files from a directory you designate
Dim counter As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
counter = My.Computer.FileSystem.GetFiles("C:\YOURDIR")
'Declare your file name
Dim myfile As String = "YOURFILE"
'Create count dim
Dim Occurrences As Integer = 0
'Check all files in the array and check them against our filename
For Each File As String In counter
If File.Contains(myfile) Then
'If a file is found, add +1
Occurrences = Occurrences + 1
End If
Next
'Display total count
MsgBox("number of files is " & Occurrences)
这将搜索您指定的路径。它将在dir中检查所有文件,如文件名。如果找到一个,它会计算它。这也会检查不区分大小写的名称,以便您可以获取文件名的所有变体。
答案 1 :(得分:0)
如下所示:
Public Shared Sub ProcessDirectory(ByVal targetDirectory As String)
Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
' do a simple if statement to see if the file name contains "myFile"
' if so add to some count variable you declare
有关GetFiles()
方法的更多参考资料,请参阅此处(这是解决问题的关键):https://msdn.microsoft.com/en-us/library/07wt70x2%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1