How to get list of files which were updated today? .NET

I have thousands of files in a FTP server which I can connect using windows explorer. Day by day, during evening, I have to find the files which were changed (uploaded) today and take their name. I'd like to develop a visual basic batch application that, just running the EXE with a parameter (date), take a list of the names of those files.

Recently I found this code here:

source = "\\ftp_my\Upload\"
searchfor = "*"
Dim dirs As String() = Directory.GetFiles(source, searchfor)
For Each file In dirs
    fileinfo = New FileInfo(file)
    If (fileinfo.LastWriteTime >= DateAdd(DateInterval.Day, -1, Date.Today)) Then
        'execute my actions
    End If

But it takes an increditable time to list all files and evaluate their properties. On the other hand , if I just make a "dir", export to excel, split the text and evaluate manually the date / files I want I finish that study earlier than the VB!

Therefore there should be a command that list the files ordered by date DESC during a resonable period, is there?


A couple of thing I noticed that can slow your iteration down.

You're casting each file name to a fileinfo object instead of using a collection of fileinfo objects.

You're calculating the target date to check for, for each file, instead of calculating it once.

Here's a method to do what you want using LINQ that will find 1000 files(worst case scenario), on a mapped network drive, in less than 5 seconds:

    Dim source = New DirectoryInfo("\\ftp_my\Upload\")
    Dim searchfor = "*"
    Dim TargetDate = DateAdd(DateInterval.Day, -1, Date.Today)
    Dim dirs = (From f As FileInfo In source.GetFiles(searchfor)
                Where f.CreationTime >= TargetDate
                Select f).ToList

dirs will contain all the fileinfo objects for each file you want to target.

If iterating through dirs and completing your actions on each file takes a long time then this will tell you where the time is being spent, and you can start looking at that code and start optimizing it to cut down the time.

Need Your Help

Remote Control (from the webpage) for a Media Player on remote machine?

php control media-player flowplayer

I just want a interface like a controller which can control "Play/Pause/Stop/ ..etc" for some kind of player (Flash or anything else) playing on a remote server, across "HTTP" under same domain.

Can Flash applications have a Javascript API?

javascript flash

How is the interaction between these two worlds in a browser?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.