View Full Version : sort all files in the folder
bmwmpower
04-08-2003, 01:46 PM
how i can sort the files in the folder by datecreated
ecnarongi
04-08-2003, 05:29 PM
what type of car do u drive? I have a 92 325 with the M kit high powered dual cam engine ( the M5 engine didn't fit :( ), and when I buy another car it will be a BMW, y buy anthing else.
Ok, your question, you need to use the filesystemobject something like so
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFile(filespec)
...
s = "Name: " & f.name & "<BR>"
s = s & "Created: " & f.DateCreated & "<BR>"
s = s & "Last Accessed: " & f.DateLastAccessed & "<BR>"
s = s & "Last Modified: " & f.DateLastModified
if they are in a particular folder u might have to do something like this
Set fso = CreateObject("Scripting.FileSystemObject")
Set objFolder = fso.GetFolder("path-to-folder")
Set objFiles = objFolder.Files
...
For Each objFile In objFiles 'if you need to loop through the files use this
s = "Name: " & objFile.name & "<BR>"
s = s & "Created: " & objFile.DateCreated & "<BR>"
s = s & "Last Accessed: " & objFile.DateLastAccessed & "<BR>"
s = s & "Last Modified: " & objFile.DateLastModified
next
notice how I use the "objFile" instead of "objFiles" in the loop, that is because I make the reference in the loop, does that help? if you need more help please say so
Morgoth
04-08-2003, 07:34 PM
That sounds about right.
glenngv
04-10-2003, 02:17 PM
I think the Files collection gets the files sorted by filename not by date modified. But sometimes, though, it's not sorted by filename. if the files were pasted in a folder from somewhere, whatever order it had when pasting was done, it would be the order of files in the FSO's Files collection. Weird but it happens to me, you can try it for yourself.
bmwmpower
04-12-2003, 09:44 AM
this is my code for view my files in the folder what i need is sort the files in the folder by datecreated or lastupdate
Function ShowFileList2(folderspec)
Dim fso, f, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.Files
For Each f1 in fc
s = s & "<tr>"
s = s & "<td class='dataTD' width='5%' height='15' align='center'><b><font face='Verdana' size='2'><a href='" & c & "\" & f1.name & "' target='_Blank'><img src='" & img & "'alt='View File' border='0'></font></b></td>"
s = s & "<td class='dataTD' width='150' height='10' align='left'><b><font face='Verdana' size='1'>" & f1.name & "</font></b></td>"
s = s & "<td class='dataTD' width='80' align='left' height='10'><b><font size='1' face='Verdana'>"& f1.size &"</font></b></td>"
s = s & "<td class='dataTD' width='125' align='center' height='10'><b><font size='1' face='Verdana'>" & f1.datecreated & "</font></b></td>"
s = replace(s,"\\","\")
Next
Response.Write s
End Function
this the code now how i can sort this files by datecreated or lastupdate
bmwmpower
04-29-2003, 12:41 PM
no one can help me plz how i can sort all the files in the folder by datecreated
Roy Sinclair
04-29-2003, 03:49 PM
Try creating an empty recordset object and then add each file to the recordset as a new record with each attribute you'd want to use as a separate field. Then you can use the SORT property of the recordset to re-order the records, last loop through the recordset to get the items in the specified order then close the recordset without ever having placed it into a database (or even connected to a database).
I haven't the time to try that right now but it should be possible to accomplish.
The only other way would be to fill the whole list of files into an array and then write your own sorting function.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.