PC Review


Reply
Thread Tools Rate Thread

Directory.GetFiles File Order Issue

 
 
=?Utf-8?B?U3RldmU=?=
Guest
Posts: n/a
 
      24th Aug 2005
I need to programmatically iterate over all files in a folder in order of
file name. I’m using VB.Net and Directory.GetFiles. The problem is that the
numbers are being interpreted as characters versus numbers as the default in
XP. Hence my iterations are Image1.jpg, Image10.jpg, Image11.jpg,
Image2.jpg, Image3.jpg…

I’m looking for a way to have the files in correct numeric order similar to
the XP file explorer view when sorted by the name column.
Thanks in advance!

 
Reply With Quote
 
 
 
 
cody
Guest
Posts: n/a
 
      24th Aug 2005
You have to sort the files by yourself, GetFiles cannot do it.
Parse the filename, get the number out of it and sort by the number.

"Steve" <(E-Mail Removed)> schrieb im Newsbeitrag
news:76938C82-6370-4809-9A90-(E-Mail Removed)...
>I need to programmatically iterate over all files in a folder in order of
> file name. I'm using VB.Net and Directory.GetFiles. The problem is that
> the
> numbers are being interpreted as characters versus numbers as the default
> in
> XP. Hence my iterations are Image1.jpg, Image10.jpg, Image11.jpg,
> Image2.jpg, Image3.jpg.
>
> I'm looking for a way to have the files in correct numeric order similar
> to
> the XP file explorer view when sorted by the name column.
> Thanks in advance!
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3RldmU=?=
Guest
Posts: n/a
 
      24th Aug 2005
Thanks that would work. Any idea how to handle sorting of mixed alphabetic
and alphanumeric file names so that the digits located anywhere in the
filename are treated as numbers vs. characters?

What I’m looking for is the class/api that performs the same sort by name as
in the XP File Explorer.


"cody" wrote:

> You have to sort the files by yourself, GetFiles cannot do it.
> Parse the filename, get the number out of it and sort by the number.
>
> "Steve" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:76938C82-6370-4809-9A90-(E-Mail Removed)...
> >I need to programmatically iterate over all files in a folder in order of
> > file name. I'm using VB.Net and Directory.GetFiles. The problem is that
> > the
> > numbers are being interpreted as characters versus numbers as the default
> > in
> > XP. Hence my iterations are Image1.jpg, Image10.jpg, Image11.jpg,
> > Image2.jpg, Image3.jpg.
> >
> > I'm looking for a way to have the files in correct numeric order similar
> > to
> > the XP file explorer view when sorted by the name column.
> > Thanks in advance!
> >

>
>
>

 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      24th Aug 2005
>What I’m looking for is the class/api that performs the same sort by name as
>in the XP File Explorer.


StrCmpLogical

http://msdn.microsoft.com/library/en...mplogicalw.asp



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
=?Utf-8?B?U3RldmU=?=
Guest
Posts: n/a
 
      24th Aug 2005
Thanks Cody and Mattias:
What I did was roll my own compare class that called the StrCmpLogicalW
function. Unfortunately this limits my users to XP only since it's not
available on 2000.
I need to check for string nulls but below is a code fragment to sort file
names as in the XP File Explorer:


Declare Unicode Function StrLogicalComparer Lib "shlwapi.dll" _
Alias "StrCmpLogicalW" (ByVal str1 As String, ByVal str2 As String) As
Integer

Public Class StrLogicalComparerClass
Implements IComparer

Function Compare(ByVal x As [Object], ByVal y As [Object]) As
Integer _
Implements IComparer.Compare
Dim text1, text2 As String
text1 = CStr(x)
text2 = CStr(y)
Return StrLogicalComparer(text1, text2)
End Function 'IComparer.Compare
End Class 'StrLogicalComparerClass



"Mattias Sjögren" wrote:

> >What I’m looking for is the class/api that performs the same sort by name as
> >in the XP File Explorer.

>
> StrCmpLogical
>
> http://msdn.microsoft.com/library/en...mplogicalw.asp
>
>
>
> Mattias
>
> --
> Mattias Sjögren [MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wireless issue? DNS issue? MS Update issue? WORLDe Windows XP General 1 14th Jan 2009 11:47 PM
How stop Excel file UK date order changing to US order in m.merge =?Utf-8?B?Um9nZXIgQWxkcmlkZ2U=?= Microsoft Excel Misc 1 9th Oct 2007 11:52 PM
How to get Address cards to be in order of First name and then last name (and not in "file as" order)? ship Microsoft Outlook 2 26th Sep 2006 08:58 PM
Graph reverse order changes series order but not legend order biddlea Microsoft Excel Misc 0 13th Aug 2004 12:48 PM
Explorer window file order issue E Windows XP Help 0 24th Apr 2004 04:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:32 AM.