473,574 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to sort and trim a directory list?

I am listing a set of files using the following script:

<% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
For Each directoryfile in allFiles.files
Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
directoryfile.n ame & "</a>"
Next %>

This displays great (thanks Roland!)but the (minor) problem is that the
names are WeekX.pdf where X= week of year.
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
....
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that the
".pdf" is not shown?
I imagine there is trim function I can use to remove the extension, but I
have no clue how to sort these numerically this way.
Jul 22 '05 #1
13 2338
you cannot easily sort them numerically because of the way they are named
(I dont think.. but I am tired so maybe I am not thinking right)

it they were named more like this like this you could

Week001.pdf
Week010.pdf
Week011.pdf
Week012.pdf

then on to the next question

easiest way to remobe the ".pdf" is with a replace stament on each one

replace(whateve r,".pdf","")

replacing the ".pdf" with nothing
".:mmac:." <lost@sea> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
I am listing a set of files using the following script:

<% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
For Each directoryfile in allFiles.files
Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
directoryfile.n ame & "</a>"
Next %>

This displays great (thanks Roland!)but the (minor) problem is that the
names are WeekX.pdf where X= week of year.
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that the
".pdf" is not shown?
I imagine there is trim function I can use to remove the extension, but I
have no clue how to sort these numerically this way.

Jul 22 '05 #2
then you get into the "how you gonna sort them" question from technical
viewpoint

either your going to put it in an array and run comlxs sorting functions on
it
or put it in database table and let a SQL statement do the work

".:mmac:." <lost@sea> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
I am listing a set of files using the following script:

<% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
For Each directoryfile in allFiles.files
Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
directoryfile.n ame & "</a>"
Next %>

This displays great (thanks Roland!)but the (minor) problem is that the
names are WeekX.pdf where X= week of year.
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that the
".pdf" is not shown?
I imagine there is trim function I can use to remove the extension, but I
have no clue how to sort these numerically this way.

Jul 22 '05 #3
hmmm, that sounds like more work than it's worth.
"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl...
then you get into the "how you gonna sort them" question from technical
viewpoint

either your going to put it in an array and run comlxs sorting functions
on it
or put it in database table and let a SQL statement do the work

".:mmac:." <lost@sea> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
I am listing a set of files using the following script:

<% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
For Each directoryfile in allFiles.files
Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
directoryfile.n ame & "</a>"
Next %>

This displays great (thanks Roland!)but the (minor) problem is that the
names are WeekX.pdf where X= week of year.
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that the
".pdf" is not shown?
I imagine there is trim function I can use to remove the extension, but I
have no clue how to sort these numerically this way.


Jul 22 '05 #4
well, pimpin aint easy
".:mmac:." <lost@sea> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
hmmm, that sounds like more work than it's worth.
"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl...
then you get into the "how you gonna sort them" question from technical
viewpoint

either your going to put it in an array and run comlxs sorting functions
on it
or put it in database table and let a SQL statement do the work

".:mmac:." <lost@sea> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
I am listing a set of files using the following script:

<% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
For Each directoryfile in allFiles.files
Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
directoryfile.n ame & "</a>"
Next %>

This displays great (thanks Roland!)but the (minor) problem is that the
names are WeekX.pdf where X= week of year.
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that the
".pdf" is not shown?
I imagine there is trim function I can use to remove the extension, but
I have no clue how to sort these numerically this way.



Jul 22 '05 #5
huh?

"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:uD******** ******@TK2MSFTN GP14.phx.gbl...
well, pimpin aint easy
".:mmac:." <lost@sea> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
hmmm, that sounds like more work than it's worth.
"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl...
then you get into the "how you gonna sort them" question from technical
viewpoint

either your going to put it in an array and run comlxs sorting functions
on it
or put it in database table and let a SQL statement do the work

".:mmac:." <lost@sea> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
I am listing a set of files using the following script:

<% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
For Each directoryfile in allFiles.files
Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
directoryfile.n ame & "</a>"
Next %>

This displays great (thanks Roland!)but the (minor) problem is that the
names are WeekX.pdf where X= week of year.
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that the
".pdf" is not shown?
I imagine there is trim function I can use to remove the extension, but
I have no clue how to sort these numerically this way.



Jul 22 '05 #6
it aint easy playin da game !

".:mmac:." <lost@sea> wrote in message
news:e7******** ******@tk2msftn gp13.phx.gbl...
huh?

"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:uD******** ******@TK2MSFTN GP14.phx.gbl...
well, pimpin aint easy
".:mmac:." <lost@sea> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
hmmm, that sounds like more work than it's worth.
"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl...
then you get into the "how you gonna sort them" question from technical
viewpoint

either your going to put it in an array and run comlxs sorting
functions on it
or put it in database table and let a SQL statement do the work

".:mmac:." <lost@sea> wrote in message
news:uI******** ******@TK2MSFTN GP09.phx.gbl...
>I am listing a set of files using the following script:
>
> <% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
> set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
> For Each directoryfile in allFiles.files
> Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
> directoryfile.n ame & "</a>"
> Next %>
>
> This displays great (thanks Roland!)but the (minor) problem is that
> the names are WeekX.pdf where X= week of year.
> So the list is displayed as :
> Week1.pdf
> Week10.pdf
> Week11.pdf
> Week12.pdf
> ...
> Week19.pdf
> Week2.pdf
> Week20.pdf
> etc
>
> How can I display the list numerical order and also trim it so that
> the ".pdf" is not shown?
> I imagine there is trim function I can use to remove the extension,
> but I have no clue how to sort these numerically this way.
>



Jul 22 '05 #7
tru' dat!

"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:O3******** *****@TK2MSFTNG P15.phx.gbl...
it aint easy playin da game !

".:mmac:." <lost@sea> wrote in message
news:e7******** ******@tk2msftn gp13.phx.gbl...
huh?

"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:uD******** ******@TK2MSFTN GP14.phx.gbl...
well, pimpin aint easy
".:mmac:." <lost@sea> wrote in message
news:O$******** ******@TK2MSFTN GP12.phx.gbl...
hmmm, that sounds like more work than it's worth.
"Kyle Peterson" <kp*****@hotmai l.com> wrote in message
news:eo******** ******@TK2MSFTN GP09.phx.gbl...
> then you get into the "how you gonna sort them" question from
> technical viewpoint
>
> either your going to put it in an array and run comlxs sorting
> functions on it
> or put it in database table and let a SQL statement do the work
>
>
>
> ".:mmac:." <lost@sea> wrote in message
> news:uI******** ******@TK2MSFTN GP09.phx.gbl...
>>I am listing a set of files using the following script:
>>
>> <% set directory = Server.CreateOb ject("Scripting .FileSystemObje ct")
>> set allfiles = directory.GetFo lder(Server.Map Path("/mmm/lesson/"))
>> For Each directoryfile in allFiles.files
>> Response.Write "<a href='/mmm/lesson/" & directoryfile.n ame & "'>" &
>> directoryfile.n ame & "</a>"
>> Next %>
>>
>> This displays great (thanks Roland!)but the (minor) problem is that
>> the names are WeekX.pdf where X= week of year.
>> So the list is displayed as :
>> Week1.pdf
>> Week10.pdf
>> Week11.pdf
>> Week12.pdf
>> ...
>> Week19.pdf
>> Week2.pdf
>> Week20.pdf
>> etc
>>
>> How can I display the list numerical order and also trim it so that
>> the ".pdf" is not shown?
>> I imagine there is trim function I can use to remove the extension,
>> but I have no clue how to sort these numerically this way.
>>
>
>



Jul 22 '05 #8
..:mmac:. wrote:
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that
the ".pdf" is not shown?


If the files are in a JScript array, this will suffice:

myArray.sort(fu nction(a,b){ret urn+a.replace(/\D/g,"")<+b.replac e(/\D/g,"")?-1:1})

The VBScript analog seems tedious. You could do a 2D array (text and numeric
equivalent) and sort, or perhaps a simple array with numeric values only --
sort the numbers, then reassemble filenames.

Unfortunately for you, enumerator objects (or direct access to collections
in VBScript) do not have built-in ordering.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 22 '05 #9
Alas... thanks, I will live with the ordering as is.

"Dave Anderson" <GT**********@s pammotel.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
.:mmac:. wrote:
So the list is displayed as :
Week1.pdf
Week10.pdf
Week11.pdf
Week12.pdf
...
Week19.pdf
Week2.pdf
Week20.pdf
etc

How can I display the list numerical order and also trim it so that
the ".pdf" is not shown?


If the files are in a JScript array, this will suffice:

myArray.sort(fu nction(a,b){ret urn+a.replace(/\D/g,"")<+b.replac e(/\D/g,"")?-1:1})

The VBScript analog seems tedious. You could do a 2D array (text and
numeric equivalent) and sort, or perhaps a simple array with numeric
values only -- sort the numbers, then reassemble filenames.

Unfortunately for you, enumerator objects (or direct access to collections
in VBScript) do not have built-in ordering.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message.
Use of this email address implies consent to these terms. Please do not
contact me directly or ask me to contact you directly for assistance. If
your question is worth asking, it's worth posting.

Jul 22 '05 #10

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

Similar topics

3
9336
by: Mike Zupan | last post by:
I have a list that includes files and directories ie: list = I want to sort it so it looks like this I'm just wondering if there is an easy way to do this
4
20886
by: Jake | last post by:
Im using the following code to display the contents of a directory: <% Set objFso = CreateObject("Scripting.FileSystemObject") Set objFiles = objFso.GetFolder(Server.MapPath(".")) Set fileList = objFiles.Files For Each i in fileList response.write i.name & " - " & i.DateCreated & "<br>" next %>
2
7311
by: Peter S. Guild | last post by:
Hello, I have a simple routine that uses a dataview to hold information. I need to sort these columns by section and then by desc. No matter what I do the dataview will not sort. What am I doing wrong? Language is C# ..Net framework is 1.1
1
3662
by: gj | last post by:
Hi, I'm trying to sort a dropdownlist. I tried using .Sort but that doesn't work. can anyone help me? Below is the code for creating the list. foreach (DataRow quizRow in dsMain1.Tables.Rows) {
10
6807
by: Amit | last post by:
Hi I'm having a problem using arraylist.sort. I'm using FileInfo.GetFiles() to receive a list of files from a directory. The files have a sequential number to start then theres either an "A" appended to the end of it or there isn't. For example, a file name will look like this: "1A.jpg" "2A.jpg" "3.jpg" "19A.jpg" etc. When I use...
7
4425
by: vzsnake | last post by:
Hello,everybody. One my class inhereted from System.Collections.CollectionBase in InnerList I add class B objects to InnerList and want to sort them by multiple properties. I done the sorting, BUT when my classes have equal values in property Name, and I sort the list by "name desc" or "name asc", It sort wrong! For example: (start list)...
4
4959
by: rn5a | last post by:
Can the items in a ListBox be sorted by the name of the items? The ListBox actually lists all directories & files existing in a directory on the server. Note that all the directories should be listed first followed by the files.
3
5168
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
12
5073
by: Nzsquall | last post by:
Hi, I am having trouble sorting a client contact lists by their surname. Every time when I press the "sort by surname button, it always appear alphabetical order by clients' first name, because I put them before the surname, it is the first String of the every line in the listBox. My code under the sortBySurname is private void...
0
7803
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7720
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8044
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7810
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5618
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3739
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2240
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1056
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.