473,406 Members | 2,259 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,406 software developers and data experts.

How to get files in order?

I'm using the following For Each loop to read files. How can I get the
files in either date stamp order or filename order?

For Each nntptobbs As String In Directory.GetFiles(NntpDir, "*.nntptobbs")
Dec 17 '05 #1
2 7501
You should sort the array return by GetFiles. Array.Sort method is what
you need, you might also need to implement a comparer.

Dec 17 '05 #2
"Terry Olsen" <to******@hotmail.com> schrieb:
I'm using the following For Each loop to read files. How can I get the
files in either date stamp order or filename order?


Quick and dirty:

\\\
Imports System.Collections
Imports System.IO
..
..
..
Dim FileNames() As String = Directory.GetFiles("C:\WINDOWS")
Array.Sort(FileNames, New LastWriteTimeComparer)
Me.ListBox1.DataSource = FileNames
..
..
..
Public Class LastWriteTimeComparer
Implements IComparer

Public Function Compare( _
ByVal x As Object, _
ByVal y As Object _
) As Integer Implements IComparer.Compare
Dim d As Long = _
File.GetLastWriteTime(DirectCast(x, String)).Ticks - _
File.GetLastWriteTime(DirectCast(y, String)).Ticks
Select Case d
Case Is > 0
Return 1
Case Is < 0
Return -1
Case Else
Return 0
End Select
End Function
End Class
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Dec 17 '05 #3

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

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
10
by: Chris Gordon-Smith | last post by:
I am currently revisiting the code of a C++ application and restructuring the code where appropriate to make it consistent with the overall logical design. As part of this, I am looking at the...
5
by: pooh | last post by:
I have a situation where the order of my cpp files in my g++ compile command line affects the program. Here is a simplified example: g++ -Wall -o test a.cpp b.cpp compiles, links and runs...
1
by: Jennifer | last post by:
Hi I've just recently bought a USB MP3 player, it doesn't have a display or anything fancy, it just holds the files and plays them The files play in the order they were added, which made me think...
4
by: Khoa Nguyen | last post by:
Hi, I have a requirement to process all files in a directory in chronological order. The os.listdir() function, however, lists the files in random order. Is there a similar function in Python...
6
by: p_adib | last post by:
hello. I have 3 files: parent.cpp child.cpp driver.cpp I am working in visual C++ 6.0 and have all the files in one same project. When I ask the IDE to biuld my project, it compiles the code...
3
by: Hartmut Dippon | last post by:
Hi all, I hope somebody can help me with following problem: I have an application where I can drag&drop files/dirs from within explorer onto my form. If multiple files/dirs are selected I...
1
by: sosoro | last post by:
Source ---------------------------------------- if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) {
1
by: aRTx | last post by:
<? /* Directory Listing Script - Version 2 ==================================== Script Author: Artani <artan_p@msn.com>. www.artxcenter.com REQUIREMENTS ============ This script requires...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.