-
Oct 28th, 2020, 03:44 AM
#1
Thread Starter
New Member
count only newer files in directory
i want to create a form where it counts only newer files placed in a specific directory, for example there are 5 files placed , but these files will be deleted, but there can be placed new files also. so general i want to check how may files a day is processed in a certain map
is this possible without to much code.
i know i can create an array, but this does not work as it should be..
Dim result As List(Of String) = (From s1 As String In Me.ListBox2.Items Where Not Me.ListBox1.Items.Contains(s1) Select s1).ToList()
For Each l In result
-
Oct 28th, 2020, 04:22 AM
#2
Re: count only newer files in directory
You can get all the files in a folder and then filter by creation date/time. You have to have a value to filter by though. There's no magical way to get a "newer" file without knowing what it has to be newer than. As you have provided us no information to go on in that department, I'll leave it up to you to work out how to get that value. Once you have it though, this will get you all files created after that time:
vb.net Code:
Dim folder As New DirectoryInfo(folderPath)
Dim files = folder.EnumerateFiles.Where(Function(fi) fi.CreationTime > thresholdTime).ToArray()
files is then an array of FileInfo objects and you can use them as you wish.
-
Oct 28th, 2020, 04:24 AM
#3
Thread Starter
New Member
Re: count only newer files in directory
Originally Posted by jmcilhinney
You can get all the files in a folder and then filter by creation date/time. You have to have a value to filter by though. There's no magical way to get a "newer" file without knowing what it has to be newer than. As you have provided us no information to go on in that department, I'll leave it up to you to work out how to get that value. Once you have it though, this will get you all files created after that time:
vb.net Code:
Dim folder As New DirectoryInfo(folderPath)
Dim files = folder.EnumerateFiles.Where(Function(fi) fi.CreationTime > thresholdTime).ToArray()
files is then an array of FileInfo objects and you can use them as you wish.
thx i will give it a try
-
Oct 28th, 2020, 07:54 AM
#4
Thread Starter
New Member
Re: count only newer files in directory
after testing i finaly ended with some other code, wich works in my situation, thx anyway
Code:
Imports System.IO
Imports System
Imports System.Diagnostics
Imports System.Threading
Public Class Form1
Public watchfolder As FileSystemWatcher
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
watchfolder = New System.IO.FileSystemWatcher()
watchfolder.Path = "d:\jb\"
watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes
AddHandler watchfolder.Created, AddressOf logchange
watchfolder.EnableRaisingEvents = True
End Sub
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.ChangeType = IO.WatcherChangeTypes.Created Then
GlobalVariables.teller2 = GlobalVariables.teller2 + 1
Invoke(New SetTextDel(AddressOf SetText), "File ")
End If
End Sub
Private Delegate Sub SetTextDel(ByVal msg As String)
Private Sub SetText(ByVal msg As String)
TextBox1.Text = GlobalVariables.teller2
End Sub
Public Class GlobalVariables
Public Shared Property teller2 As Integer
End Class
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|