DIR() sort by file LastChange
Posted
#1
(In Topic #526)
Regular

Posted
Regular

This should give you the LastModified date, providing you can still access the file system using the file name references in your array.
Posted
Guru

You have to add your own sorting routine to your code. wiki shows how /comp/gb.qt4/gridview/sorted - Gambas Documentation
populate the gridview with filenames on column 1 and modified dates on column 2 then with GridView1.Colums.Sort = 1 set you can use it to sort by date.
Posted
Regular

Bear in mind I'm looking for an array of file names sorted by each file's LastChange value.
I found this posting from way back. Its 'messy'. Add the LastModified date string to the file name, sort it then remove the date part.
Private Procedure SortArray(sPath As String, sOriginal As String[]) As String[]
Dim sTempArray, sReturnArray As New String[]
Dim s As String
For Each s In sOriginal
sTempArray.Add(Stat(sPath &/ s).LastModified & "#" & s)
Next
sTempArray = sTempArray.Sort()
For Each s In sTempArray
sReturnArray.Add(Split(s, "#")[1])
Next
Return sReturnArray
End
In case this is my last post here for this year, I'd like to say that I've found this forum to be very helpful over the years so thank you all you responders!
And while I'm at it, the Seasons Greetings to you!
Posted
Regular

bill-lancaster said
…Bear in mind I'm looking for an array of file names sorted by each file's LastChange value.
I found this posting from way back. Its 'messy'…
From the Dir() in your title, I assumed you didn't have the LastModified date.
If you are grabbing the file name and LastModified date at the same time, I'd recommend you save both in a 2dimentional array. That way you can re-order the list easily.
In case this is my last post here for this year, I'd like to say that I've found this forum to be very helpful over the years so thank you all you responders!
And while I'm at it, the Seasons Greetings to you!
…and a Merry Christmas to you too Bill!
Posted
Guru

I have just seen Steve's input. His idea of a 2 dimensional array is similar but slightly different to my solution.
Get the list of the file names in an array. sFiles = Dir(User.Home)
Add to each file name in the array its Last Modified Date and a separator(`) so IMG_1234.png becomes 2020/12/23 16:00:00`IMG_1234.png
Sorting the array will put it in date order.
Display the array, splitting each item by its separator.
<IMG src="https://www.cogier.com/gambas/FileDateOrder.png">
</IMG>Run this in a Graphical application
Code (gambas)
- ' Gambas class file
- SetUpForm
- 'sFiles.Sort(gb.Ascent) 'Latest at the bottom
- sFiles.Sort(gb.Descent) 'Latest at the top
- .Width = 750
- .Height = 550
- .Arrangement = Arrange.Vertical
- .Padding = 5
- .Text = "Sort files by date"
- .Rows.Count = sFiles.Count
- .Columns.Count = 2
- .Columns[0].Text = "Time and date"
- .Columns[1].Text = "File name"
Posted
Guru

Posted
Guru

BruceSteers said
It has it's down sides: -
3C-3E-EG.mp3
Ode\ to\ Joy.mp3
Brake1.mp3
Lady\ Madonna.mp3
Track\ 1.mp3
vlc-record-2019-04-16-09h00m04s-rattle.mp3-.mp3
vlc-record-2019-04-16-08h59m55s-rattle.mp3-.mp3
Charles\ Bolt\ -\ Far\ and\ Beyond-wce9cuixaM0.flac
Charles\ Bolt\ -\ Far\ and\ Beyond-wce9cuixaM0.opus
Brad\ Sucks\ -\ Making\ Me\ Nervous.mp3
Lady\ Madonna.wav
Peer\ Gynt.mmf
Track\ 1.wav
Sweet\ child\ of\ mine\ -\ Jizzy\ Pearl.ogg
Alice\ Cooper\ -\ Poison.ogg
ZAlice\ Cooper\ -\ Poison.ogg
Ann\ Nesby\ -\ I\ Can't\ Explain\ It.mp3
Barbara\ Dickson\ -\ Caravans.mp3
Here\ Is\ The\ News.m4a
Last\ Train\ To\ London.m4a
Brad\ Sucks\ -\ Dropping\ out\ of\ school.ogg
Duffy\ -\ Stepping\ Stone.ogg
15.\ Twist\ in\ My\ Sobriety.ogg
Posted
Guru

cogier said
BruceSteers said
It has it's down sides: -
3C-3E-EG.mp3
Ode\ to\ Joy.mp3
Brake1.mp3
Lady\ Madonna.mp3
Track\ 1.mp3
vlc-record-2019-04-16-09h00m04s-rattle.mp3-.mp3
vlc-record-2019-04-16-08h59m55s-rattle.mp3-.mp3
Charles\ Bolt\ -\ Far\ and\ Beyond-wce9cuixaM0.flac
Charles\ Bolt\ -\ Far\ and\ Beyond-wce9cuixaM0.opus
Brad\ Sucks\ -\ Making\ Me\ Nervous.mp3
Lady\ Madonna.wav
Peer\ Gynt.mmf
Track\ 1.wav
Sweet\ child\ of\ mine\ -\ Jizzy\ Pearl.ogg
Alice\ Cooper\ -\ Poison.ogg
ZAlice\ Cooper\ -\ Poison.ogg
Ann\ Nesby\ -\ I\ Can't\ Explain\ It.mp3
Barbara\ Dickson\ -\ Caravans.mp3
Here\ Is\ The\ News.m4a
Last\ Train\ To\ London.m4a
Brad\ Sucks\ -\ Dropping\ out\ of\ school.ogg
Duffy\ -\ Stepping\ Stone.ogg
15.\ Twist\ in\ My\ Sobriety.ogg
okay use the -N flag too to remove the quotes
-1Nt
Posted
Guru

-Q, –quote-name enclose entry names in double quotes
–quoting-style=WORD use quoting style WORD for entry names:
literal, locale, shell, shell-always,
shell-escape, shell-escape-always, c, escape
(overrides QUOTING_STYLE environment variable)
Of course you then just have to run through the array and remove any dirs or other filetypes you want to omit.
Not sure if dir supports just showing filenames?
you could grep filetypes from the output
"dir -1Nt /My/Dir/Path|grep .mp3"
1 guest and 0 members have just viewed this.


