-
June 10th, 2010, 02:55 AM
#1
Get files from folder in ascending order based on creation date
Hi,
I need to get files from a folder in ascending order based on the creationtime of the files under it.
Please help me.
Thanks in advance.
-
June 10th, 2010, 03:18 AM
#2
Re: Get files from folder in ascending order based on creation date
I would use the File System Object here, something like this :
Code:
Option Explicit
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim fld As Folder
Dim fil As File
Set fld = fso.GetFolder("C:\Hannes")
For Each fil In fld.Files
List1.AddItem fil.Name
Next
Set fil = Nothing
Set fld = Nothing
Set fso = Nothing
End Sub
I'd then still use the FSO to obtain the various properties of the files :
http://www.aivosto.com/visdev/fso.html
-
June 10th, 2010, 07:36 AM
#3
Re: Get files from folder in ascending order based on creation date
I would use the Shell libary or API
Some useful info in this thread
http://www.codeguru.com/forum/showthread.php?t=497321
Always use [code][/code] tags when posting code.
-
June 10th, 2010, 07:59 AM
#4
Re: Get files from folder in ascending order based on creation date
I forgot about that excellent thread.
Ignore my first post, Idris, and definitely take DataMiser's advice!
-
June 10th, 2010, 10:52 AM
#5
Re: Get files from folder in ascending order based on creation date
Yes I'd also recommend to use shell objects.
Although you have to watch out that the creation date has to be obtained explicitly. It is not direct part of the FolderItem structure.
To sort files according to creation date you could make use of a ListView control, if you want to make your search result visible anyway.
You use a two-column Report-style listview, put the name in one and the date in the second column, then let the ListView sort it for you.
If no visible control was required you need 2 Arrays, one for the filename and one for the date. You have then to write your own little sorting routine, though.
-
June 11th, 2010, 01:12 AM
#6
Re: Get files from folder in ascending order based on creation date
Thanks a lot for the comments.
Its taking a long time when i loop through the folder since i am accessing a remote path.
I tried with normal filedir control which lists the files under the folder in a quick turn around time. Is there any similar control which should get the files,filesize and filemodifiedate from a folder without looping through the folder.
-
June 11th, 2010, 06:22 AM
#7
Re: Get files from folder in ascending order based on creation date
The control is slow, use the shell or api should be about 5 times faster
Always use [code][/code] tags when posting code.
-
June 11th, 2010, 08:52 AM
#8
Re: Get files from folder in ascending order based on creation date
The control does also aloop to scan a folder.
Any loop written in VB using shell objects shouldn't be any longer than filelistbox.
I'd advise to fill a ListView with Names and Dates and let the listview do the sorting according to the column you select as sortindex.
-
June 14th, 2010, 02:48 AM
#9
Re: Get files from folder in ascending order based on creation date
Can i have a code using shell object to loop through the directory.
Currently i am using FSO object.
Thanks a lot.
-
June 14th, 2010, 07:23 AM
#10
Re: Get files from folder in ascending order based on creation date
Look at the link I posted,
Always use [code][/code] tags when posting code.
-
June 14th, 2010, 08:37 AM
#11
Re: Get files from folder in ascending order based on creation date
Thank a lot for the comments.
Is there any option using FSO object to get the last accessed/created filetime from a remote folder without looping through the folder
-
June 14th, 2010, 08:44 AM
#12
Re: Get files from folder in ascending order based on creation date
It seems as if we came accross a language barrier or comprehension barrier or something
Look at the link posted by DataMiser in Post #3.
We cannot put it into simpler English.
The thread in the link DataMiser supplied shows all relevant information. Look there, try the things. We do not hand code out on a silver platter.
Do some effort. What is so complicated? What is so hard?
Look at the link posted by DataMiser in Post #3!
-
June 14th, 2010, 11:24 AM
#13
Re: Get files from folder in ascending order based on creation date
The problem seems to be that the shell objects do not provide direct access to the creation date. Documentation is a bit thin there.
But the shell32.Folder provides the GetDetailsOf() method which you'd have to use like this:
Assumed you have the folder which holds the files you'd want to list.
Further assume you want to put names and dates in a three-column-ListView named LV
Code:
Private Sub FillListView(LV As ListView, Fold As Shell32.Folder)
Dim fit As Shell32.FolderItem
Dim lit As ListItem
For Each fit In Fold.Items
If fit.IsFileSystem And Not fit.IsFolder Then 'it is a file
Set lit = LV.ListItems.Add(, , fit.Name)
lit.SubItems(1) = Fold.GetDetailsOf(fit, 3) 'get creation date
lit.SubItems(2) = Fold.GetDetailsOf(fit, 4) 'get modification date
End If
Next
End Sub
You can set LV to be sorted and sort index to be 1, which is the creation date column then.
-
June 16th, 2010, 12:00 AM
#14
Re: Get files from folder in ascending order based on creation date
Hi All,
Thanks a lot for the help.
Atlast my expectation is fulfilled with shell32.
Thanks again.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|