473,395 Members | 1,846 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,395 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 4906
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

5
by: Raj | last post by:
Hi all, Can anyone help me with a script which would delete files or move them to a different folder at some scheduled time..! Please.....!!! Thanks in advance...
3
by: Krish | last post by:
I have requirement, that i get one big chunk of text file. This text file will have has information, that on finding "****End of Information****", i have to split them individual text file with our...
5
by: Mitchell S. Honnert | last post by:
Is there a way, given the full path of a folder on a network, that one can programatically tell if you have Read access to that folder? I have an application where the user is able to select a...
0
by: whitemoss | last post by:
Hi All, I had written a code to read a file and insert it's contents to the database. Since I will receive 3 files every hour, so, this program should read those files and insert the contents...
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...
4
by: Jim | last post by:
I have the following piece of code: Directory.CreateDirectory(myDir); DirectoryInfo lDir = new DirectoryInfo(myDir); lDir.Attributes = FileAttributes.Normal; When this code runs, my directory...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
8
by: =?Utf-8?B?QnJ5YW4=?= | last post by:
Hello group. I have some code (given to me), but I don't know alot about ASP, so I was hoping someone here can help. Running on Win 2008 server. The code below will scan a folder and subfolder...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.