jujubeans69
New Member
- Joined
- Aug 17, 2012
- Messages
- 43
I am currenlty using a "simple" macro to count the number of files in a particular folder. I was wondering if anyone can help me modify/adjust it so it only counts the number of files with today's date. Many thanks in advance!
My script:
I was able to find this using google, but am not sure how to incorporate it, or even if it would work.
If you are on .NET 2 as commented, you don't have Linq and <CODE>Directory.EnumerateFiles</CODE>, then use <CODE>GetFiles</CODE> and loops:
<CODE>
</CODE>
My script:
Rich (BB code):
Sub DTSx()
Dim srch1 As String, found1 As Integer, i1 As Integer
For i1 = 4 To 4
srch1 = "\\root\inbound\" & "*.835"
found1 = 0
If Dir(srch1) <> "" Then 'is there such a file?
Do
found1 = found1 + 1
Loop While Dir() <> "" 'are there more such files
End If
Sheets("DTS Xmissions").Range("C" & i1) = found1
Next i1
I was able to find this using google, but am not sure how to incorporate it, or even if it would work.
Rich (BB code):
Dim csvFiles = From csv In Directory.EnumerateFiles("DirectoryPath", "*Test.csv", IO.SearchOption.AllDirectories)
Where File.GetCreationTime(csv).Date = Date.Today
For Each csvPath In csvFiles
Console.WriteLine(csvPath)
Next
If you are on .NET 2 as commented, you don't have Linq and <CODE>Directory.EnumerateFiles</CODE>, then use <CODE>GetFiles</CODE> and loops:
<CODE>
Rich (BB code):
Dim csvFilesToday = New List(Of String)
For Each csv In Directory.GetFiles("DirectoryPath", "*Test.csv", IO.SearchOption.AllDirectories)
If File.GetCreationTime(csv).Date = Date.Today Then
csvFilesToday.Add(csv)
End If
Next