473,379 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Accessing collections with FSO

I have a folder object whose associated files collection I can iterate
through using a "for each / next" loop to retrieve all the file names
individually. I cannot however directly access the n'th item in the files
collection? Here is my code so far;

' create FSO & folder objects
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFld 'folder object &
objFld = objFSO.GetFolder(Server.MapPath("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.Item(4).Name

This code snippet gives me a "parameter is incorrect" on the "return" line.

Any ideas? Thanks

Steve
Nov 21 '05 #1
6 1548
hiya...

for starters i would use the My.Computer.FileSystem object, because the
Scripting.FileSystemObject is extremely slow in .NET.

' make a read-only collection:
Dim files As ReadOnlyCollection(Of String)

' use My.Computer.FileSystem.GetFiles to return a ReadOnlyCollection of all
files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.FileSystem.GetFiles( folderpath,
FileIO.SearchOption.SearchAllSubDirectories, anyWildcards)

' Display the FIFTH item:
msgbox files.item(4)
HTH

"Steve" <sj****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a folder object whose associated files collection I can iterate
through using a "for each / next" loop to retrieve all the file names
individually. I cannot however directly access the n'th item in the files
collection? Here is my code so far;

' create FSO & folder objects
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFld 'folder object &
objFld = objFSO.GetFolder(Server.MapPath("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.Item(4).Name

This code snippet gives me a "parameter is incorrect" on the "return"
line.

Any ideas? Thanks

Steve

Nov 21 '05 #2
Hi Steve,

It seems that Files.Item() property requires name of the file passed,
bot it's number, e.g.:

~
MessageBox.Show(fso.GetFolder("C:\").Files.Item("B OOTLOG.TXT").Path)
~

Indeed, what is file #4? The don't have any order.
Also, I strongly advice you to use System.IO.Directory class for such
kind of jobs.

Hope this helps,
Roman

"Steve" <sj****@hotmail.com> сообщил/сообщила в новостях следующее:
news:#5**************@TK2MSFTNGP11.phx.gbl...
I have a folder object whose associated files collection I can iterate
through using a "for each / next" loop to retrieve all the file names
individually. I cannot however directly access the n'th item in the files collection? Here is my code so far;

' create FSO & folder objects
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFld 'folder object &
objFld = objFSO.GetFolder(Server.MapPath("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.Item(4).Name

This code snippet gives me a "parameter is incorrect" on the "return" line.
Any ideas? Thanks

Steve


Nov 21 '05 #3
Hi, and thanks for the response & ideas.

I seem only able to "Dim" my collections as "ReadOnlyCollectionBase" &

your "files = My.Computer...." assignment gives me the "Name 'my' is not
declared" error.

I probably should mention that I am trying to implement this functionality
into a web control.

Any other ideas? Thanks, Steve

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
hiya...

for starters i would use the My.Computer.FileSystem object, because the
Scripting.FileSystemObject is extremely slow in .NET.

' make a read-only collection:
Dim files As ReadOnlyCollection(Of String)

' use My.Computer.FileSystem.GetFiles to return a ReadOnlyCollection of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.FileSystem.GetFiles( folderpath,
FileIO.SearchOption.SearchAllSubDirectories, anyWildcards)

' Display the FIFTH item:
msgbox files.item(4)
HTH

"Steve" <sj****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a folder object whose associated files collection I can iterate
through using a "for each / next" loop to retrieve all the file names
individually. I cannot however directly access the n'th item in the files
collection? Here is my code so far;

' create FSO & folder objects
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFld 'folder object &
objFld = objFSO.GetFolder(Server.MapPath("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.Item(4).Name

This code snippet gives me a "parameter is incorrect" on the "return"
line.

Any ideas? Thanks

Steve


Nov 21 '05 #4
what version of .NET are you using??

"Steve" <sj****@hotmail.com> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...
Hi, and thanks for the response & ideas.

I seem only able to "Dim" my collections as "ReadOnlyCollectionBase" &

your "files = My.Computer...." assignment gives me the "Name 'my' is not
declared" error.

I probably should mention that I am trying to implement this functionality
into a web control.

Any other ideas? Thanks, Steve

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
hiya...

for starters i would use the My.Computer.FileSystem object, because the
Scripting.FileSystemObject is extremely slow in .NET.

' make a read-only collection:
Dim files As ReadOnlyCollection(Of String)

' use My.Computer.FileSystem.GetFiles to return a ReadOnlyCollection of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.FileSystem.GetFiles( folderpath,
FileIO.SearchOption.SearchAllSubDirectories, anyWildcards)

' Display the FIFTH item:
msgbox files.item(4)
HTH

"Steve" <sj****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a folder object whose associated files collection I can iterate
through using a "for each / next" loop to retrieve all the file names
individually. I cannot however directly access the n'th item in the files
collection? Here is my code so far;

' create FSO & folder objects
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFld 'folder object &
objFld = objFSO.GetFolder(Server.MapPath("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.Item(4).Name

This code snippet gives me a "parameter is incorrect" on the "return"
line.

Any ideas? Thanks

Steve



Nov 21 '05 #5
..Net version 1.1

XP Pro with SP2

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
what version of .NET are you using??

"Steve" <sj****@hotmail.com> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...
Hi, and thanks for the response & ideas.

I seem only able to "Dim" my collections as "ReadOnlyCollectionBase" &

your "files = My.Computer...." assignment gives me the "Name 'my' is not
declared" error.

I probably should mention that I am trying to implement this
functionality into a web control.

Any other ideas? Thanks, Steve

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
hiya...

for starters i would use the My.Computer.FileSystem object, because the
Scripting.FileSystemObject is extremely slow in .NET.

' make a read-only collection:
Dim files As ReadOnlyCollection(Of String)

' use My.Computer.FileSystem.GetFiles to return a ReadOnlyCollection of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.FileSystem.GetFiles( folderpath,
FileIO.SearchOption.SearchAllSubDirectories, anyWildcards)

' Display the FIFTH item:
msgbox files.item(4)
HTH

"Steve" <sj****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
I have a folder object whose associated files collection I can iterate
through using a "for each / next" loop to retrieve all the file names
individually. I cannot however directly access the n'th item in the
files collection? Here is my code so far;

' create FSO & folder objects
Dim objFSO
objFSO = Server.CreateObject("Scripting.FileSystemObject")
Dim objFld 'folder object &
objFld = objFSO.GetFolder(Server.MapPath("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.Item(4).Name

This code snippet gives me a "parameter is incorrect" on the "return"
line.

Any ideas? Thanks

Steve



Nov 21 '05 #6
ah, the solution i gave works in .net 2.0

"Steve" <sj****@hotmail.com> wrote in message
news:Ot**************@TK2MSFTNGP11.phx.gbl...
.Net version 1.1

XP Pro with SP2

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
what version of .NET are you using??

"Steve" <sj****@hotmail.com> wrote in message
news:Ol**************@TK2MSFTNGP12.phx.gbl...
Hi, and thanks for the response & ideas.

I seem only able to "Dim" my collections as "ReadOnlyCollectionBase" &

your "files = My.Computer...." assignment gives me the "Name 'my' is not
declared" error.

I probably should mention that I am trying to implement this
functionality into a web control.

Any other ideas? Thanks, Steve

"Wicksy" <wi*****@nospam-yahoo.com> wrote in message
news:dh**********@news.freedom2surf.net...
hiya...

for starters i would use the My.Computer.FileSystem object, because the
Scripting.FileSystemObject is extremely slow in .NET.

' make a read-only collection:
Dim files As ReadOnlyCollection(Of String)

' use My.Computer.FileSystem.GetFiles to return a ReadOnlyCollection of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.FileSystem.GetFiles( folderpath,
FileIO.SearchOption.SearchAllSubDirectories, anyWildcards)

' Display the FIFTH item:
msgbox files.item(4)
HTH

"Steve" <sj****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
>I have a folder object whose associated files collection I can iterate
>through using a "for each / next" loop to retrieve all the file names
>individually. I cannot however directly access the n'th item in the
>files collection? Here is my code so far;
>
> ' create FSO & folder objects
> Dim objFSO
> objFSO = Server.CreateObject("Scripting.FileSystemObject")
> Dim objFld 'folder object &
> objFld = objFSO.GetFolder(Server.MapPath("/test"))
>
> ' now directly access file # 4 & return file name
> Return objFld.Files.Item(4).Name
>
> This code snippet gives me a "parameter is incorrect" on the "return"
> line.
>
> Any ideas? Thanks
>
> Steve
>
>



Nov 21 '05 #7

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

Similar topics

6
by: David D. | last post by:
I want to be able to access cells within an HTML table, via computed row number and column number. I was considering using oTableID.children and oTR.children arrays. My question is what...
15
by: Christopher Benson-Manica | last post by:
When are named elements written with script accessible to script? <html><head><script type="text/javascript"> function ready() { alert( document.getElementsByName("div").length ); }...
6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
3
by: AdamM | last post by:
Hi all, When I run my VbScript, I get the error: "ActiveX component can't create object: 'getobject'. Error 800A01AD". Any ideas what I did wrong? Here's my VBScript: dim o set...
6
by: mumrah | last post by:
When getting different elements out of an array in JS, i know array.item(0) and array both return the 0th element. My question, will this work in any instance?
7
by: hummh | last post by:
Hello out there, Iґm making my first steps with ASP.NET 2.0 and have he following problem: Iґve implemented a Web User Control that sits in the root of my ASP.NET Website. I want to use the...
6
by: Steve Barnett | last post by:
I have created a user control that includes the following field: protected TreeColumn columns = new TreeColumn; This is accessed via an accessor as follows: pubilc TreeColumn Columns { get {...
2
by: newscorrespondent | last post by:
I have a list declared: public System.Collections.Generic.SortedList<int, System.Collections.Generic.List<MTGTracer ActiveList = new SortedList<int,List<MTGTracer>>(); The key is an integer...
9
by: The.Relinator | last post by:
I need to retrieve a string from the clipboard in a console application, I have tried many methods but all seem to return a null value, any help regarding this issue would be greatly appreciated
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.