PC Review


Reply
Thread Tools Rate Thread

Counting backwards through the File System Object files collection

 
 
signon77
Guest
Posts: n/a
 
      25th Nov 2008
Here's the deal.

I'm attempting to move backwards through the fso files collection but
getting an "invalid procedure call" error. Here's the code I'm
struggling with:

Dim objFso As FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim z As Long
Set dTPlusOneFiles = New Dictionary

'Count backwards through the files collection to get the four most
recently created files
For z = objFolder.Files.Count To 1 Step -1
Set objFile = objFolder.Files(z)
dTPlusOneFiles.Add objFile.Name, objFile.DateCreated
Next z

Strangely the error message occurs at this point: "Set objFile =
objFolder.Files(z)"

Any assistance will be gratefully appreciated.

Rob
 
Reply With Quote
 
 
 
 
James Cone
Guest
Posts: n/a
 
      25th Nov 2008
Rob,
You will have to use a For | Each construct to iterate the Files collection
and fill the Dictionary object.
Once that is complete, you could add the Dictionary "Items" or "Keys"
array to a worksheet and sort it.
--
Jim Cone
Portland, Oregon USA


"signon77"
wrote in message
Here's the deal.
I'm attempting to move backwards through the fso files collection but
getting an "invalid procedure call" error. Here's the code I'm
struggling with:

Dim objFso As FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim z As Long

Set dTPlusOneFiles = New Dictionary
'Count backwards through the files collection to get the four most
recently created files
For z = objFolder.Files.Count To 1 Step -1
Set objFile = objFolder.Files(z)
dTPlusOneFiles.Add objFile.Name, objFile.DateCreated
Next z

Strangely the error message occurs at this point: "Set objFile =
objFolder.Files(z)"
Any assistance will be gratefully appreciated.
Rob
 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      26th Nov 2008
Have you tried

objFolder.Files.Item(z)

Tim


"signon77" <(E-Mail Removed)> wrote in message
news:d2e24580-ce1d-4eea-98ac-(E-Mail Removed)...
> Here's the deal.
>
> I'm attempting to move backwards through the fso files collection but
> getting an "invalid procedure call" error. Here's the code I'm
> struggling with:
>
> Dim objFso As FileSystemObject
> Dim objFolder As Folder
> Dim objFile As File
> Dim z As Long
> Set dTPlusOneFiles = New Dictionary
>
> 'Count backwards through the files collection to get the four most
> recently created files
> For z = objFolder.Files.Count To 1 Step -1
> Set objFile = objFolder.Files(z)
> dTPlusOneFiles.Add objFile.Name, objFile.DateCreated
> Next z
>
> Strangely the error message occurs at this point: "Set objFile =
> objFolder.Files(z)"
>
> Any assistance will be gratefully appreciated.
>
> Rob



 
Reply With Quote
 
Jim Cone
Guest
Posts: n/a
 
      26th Nov 2008
Tim,
I did. Did you? <g>
--
Jim Cone
Portland, Oregon USA


"Tim Williams"
wrote in message

Have you tried
objFolder.Files.Item(z)
Tim

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      27th Nov 2008
Nope!

Tim

"Jim Cone" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Tim,
> I did. Did you? <g>
> --
> Jim Cone
> Portland, Oregon USA
>
>
> "Tim Williams"
> wrote in message
>
> Have you tried
> objFolder.Files.Item(z)
> Tim
>



 
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
Adding class object to collection repeats same object through collection? Erazmus Microsoft Excel Programming 2 17th Sep 2007 04:35 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
info on Hidden/System object files AND .odc file =?Utf-8?B?Um9iZXJ0IEFuZGVyc29u?= Microsoft Access 1 9th Apr 2005 02:22 AM
system.object to namevalue collection Charles Microsoft ASP .NET 1 29th Aug 2003 03:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:06 PM.