473,408 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How do I read all the files in a folder sorted by Created Date Time (Using System.IO).

Dear All,

I am developing 2 applications.

The first application will keep on generate a new file in a span of 30
milliseconds with some valid data inside (This code is written in C).

The second application (A Windows Service written in VB.NET) will keep on
read the file from the same folder and update the database. My problem is
that the second appliaction will have to read the files in the same order
(Created Date Time in milliseconds) in which the fisrt application has
written.

I tried using System.IO.Directory and System.IO.DirectoryInfo. In this I am
able to get the file CreatedTime but not able to order it by the Created
Time and then do the processing. As of now I am reading the File, taking the
created time, putting this in a array, sorting it by DateTime and then
processing the file.

Is there any way I can do this in VB.NET/C# ?

Thanks and Regards,

Peri

Feb 27 '07 #1
1 9202
On Feb 27, 4:02 am, "Peri" <p...@CSPL.comwrote:
Dear All,

I am developing 2 applications.

The first application will keep on generate a new file in a span of 30
milliseconds with some valid data inside (This code is written in C).

The second application (A Windows Service written in VB.NET) will keep on
read the file from the same folder and update the database. My problem is
that the second appliaction will have to read the files in the same order
(Created Date Time in milliseconds) in which the fisrt application has
written.

I tried using System.IO.Directory and System.IO.DirectoryInfo. In this I am
able to get the file CreatedTime but not able to order it by the Created
Time and then do the processing. As of now I am reading the File, taking the
created time, putting this in a array, sorting it by DateTime and then
processing the file.

Is there any way I can do this in VB.NET/C# ?
Here is some VB.NET 2005 code I do it with. Note in my case, I am
sorting the list DESCENDING.

Friend Sub Purge_Log(ByVal sDirectory As String, ByVal
sSearchPattern As String)
'
' process the purging of old logs based on the
Logging.NumberToKeep property
' NOTE: The current log file is not actually created unless a
record is actually written to it
'
Dim colLogFiles As New List(Of clsLogFile)
Dim fi As FileInfo
Dim myLogFile As clsLogFile
Dim sFiles() As String
Dim sFile As String
Dim i As Integer

sFiles = Directory.GetFiles(sDirectory, sSearchPattern)
For Each sFile In sFiles
fi = New FileInfo(sFile)
myLogFile = New clsLogFile
myLogFile.FileName = fi.FullName
myLogFile.DateCreated = fi.CreationTime
colLogFiles.Add(myLogFile)
Next
colLogFiles.Sort(AddressOf CompareDateCreated)
i = 0
For Each myLogFile In colLogFiles
i += 1
If i myDTC.Logging.NumberToKeep Then
If File.Exists(myLogFile.FileName) Then
File.Delete(myLogFile.FileName)
If myDTC.Logging.LoggingLevel =
clsDataTransferConfiguration.LoggingLevels.TESTING Or
myDTC.Logging.LoggingLevel =
clsDataTransferConfiguration.LoggingLevels.VERBOSE Then
Message = "Purged Log File " &
myLogFile.FileName & vbCrLf
MyLog.LogInfo(Message)
End If
End If
End If
Next

End Sub

Friend Function CompareDateCreated(ByVal x As clsLogFile, ByVal y
As clsLogFile) As Integer

If x.DateCreated y.DateCreated Then Return -1
If x.DateCreated < y.DateCreated Then Return 1
Return 0

End Function

Feb 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Don | last post by:
Hi all, With regards to the following, how do I append the datetimestamp to the filenames in the form? The files are processed using the PHP script that follows below. Thanks in advance,...
1
by: George LAZAR | last post by:
how can I change the system current date (time) using c#? thank you George
1
by: Ruy Castelli | last post by:
I created a ASP.NET page using C# and I'm using two components to access a MS-Access database, which are: - oleDbConnection - oleDataAdapter The MS-Access database is in the correct directory...
2
by: markric | last post by:
I recently posted this message to microsoft.public.dotnet.framework.aspnet.webservices, but received no response, so I'm trying here in this group. I could really use some feedback. I'm working...
1
by: Peri | last post by:
Dear All, I am developing 2 applications. The first application will keep on generate a new file in a span of 30 milliseconds with some valid data inside (This code is written in C). The...
7
by: JamesG | last post by:
Hi, I need to convert the current time to the format "hh:mm:ss" and date to the format "yyyy-MM-dd". The result of both conversions needs to be of System.DateTime format. I've tried using...
1
by: questionit | last post by:
I am trying to use DateCreated property of RecordSet but getting error. Set db = CurrentDb Set rst = db.OpenRecordset("SELECT name FROM Table1") If i try: While rst.EOF = False ...
2
by: baker_tony | last post by:
Hi, is there any way of getting details (such as last modified/ created date/time) of a file located on the web? E.g I'd like to know when the file "http://www.myWebSite.com/ update.txt" was...
3
by: brendanmcdonagh | last post by:
I have these values in an array after using split $alltogether = $day . "," . $month . "," . $hour . "," . $minutes . ","; $arr=split(",",$alltogether); // splitting the array $d=$arr; //...
0
by: beginerVB | last post by:
I am able to query/read the "Application" event log using System.Management classes in VB.net 2005 (win xp) But I have problem reading the "Message" / "description" of my custom event log. I am...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.