473,789 Members | 2,431 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.CreateOb ject("Scripting .FileSystemObje ct")
Dim objFld 'folder object &
objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

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

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

Any ideas? Thanks

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

for starters i would use the My.Computer.Fil eSystem object, because the
Scripting.FileS ystemObject is extremely slow in .NET.

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

' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of all
files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.Fil eSystem.GetFile s( folderpath,
FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)

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

"Steve" <sj****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.CreateOb ject("Scripting .FileSystemObje ct")
Dim objFld 'folder object &
objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.It em(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.It em("BOOTLOG.TXT ").Path)
~

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

Hope this helps,
Roman

"Steve" <sj****@hotmail .com> ñîîáùèë/ñîîáùèëà â íîâîñòÿõ ñëåäóþùåå:
news:#5******** ******@TK2MSFTN GP11.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.CreateOb ject("Scripting .FileSystemObje ct")
Dim objFld 'folder object &
objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.It em(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 "ReadOnlyCollec tionBase" &

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*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
hiya...

for starters i would use the My.Computer.Fil eSystem object, because the
Scripting.FileS ystemObject is extremely slow in .NET.

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

' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.Fil eSystem.GetFile s( folderpath,
FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)

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

"Steve" <sj****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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
individuall y. 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.CreateOb ject("Scripting .FileSystemObje ct")
Dim objFld 'folder object &
objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.It em(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******** ******@TK2MSFTN GP12.phx.gbl...
Hi, and thanks for the response & ideas.

I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &

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*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
hiya...

for starters i would use the My.Computer.Fil eSystem object, because the
Scripting.FileS ystemObject is extremely slow in .NET.

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

' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.Fil eSystem.GetFile s( folderpath,
FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)

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

"Steve" <sj****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.CreateOb ject("Scripting .FileSystemObje ct")
Dim objFld 'folder object &
objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.It em(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*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
what version of .NET are you using??

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

I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &

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*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
hiya...

for starters i would use the My.Computer.Fil eSystem object, because the
Scripting.FileS ystemObject is extremely slow in .NET.

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

' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.Fil eSystem.GetFile s( folderpath,
FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)

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

"Steve" <sj****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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
individuall y. 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.CreateOb ject("Scripting .FileSystemObje ct")
Dim objFld 'folder object &
objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

' now directly access file # 4 & return file name
Return objFld.Files.It em(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******** ******@TK2MSFTN GP11.phx.gbl...
.Net version 1.1

XP Pro with SP2

"Wicksy" <wi*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
what version of .NET are you using??

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

I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &

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*****@nosp am-yahoo.com> wrote in message
news:dh******** **@news.freedom 2surf.net...
hiya...

for starters i would use the My.Computer.Fil eSystem object, because the
Scripting.FileS ystemObject is extremely slow in .NET.

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

' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
all files in a folder.
' you can change the 2nd and 3rd parameters to suit:
files = My.Computer.Fil eSystem.GetFile s( folderpath,
FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)

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

"Steve" <sj****@hotmail .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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
>individual ly. 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.CreateOb ject("Scripting .FileSystemObje ct")
> Dim objFld 'folder object &
> objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
>
> ' now directly access file # 4 & return file name
> Return objFld.Files.It em(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
7103
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 browsers and browser versions support this? If the children constructs are not fairly universally supported, then what is a better approach to doing this?
15
2101
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 ); } </script></head> <body onload="ready()"> <script type="text/javascript"> document.open();
6
2746
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 called "form1", and I have selects called "PORTA", "PORTB" ... etc...
3
3347
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 o=getobject(,"ConsoleApplication2.Program") msgbox o.TestString
6
2381
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
5678
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 Type of the control in a class that´s under the App_code folder. As with ASP.NET 1.x, I tried to reference the Control via the using keyword - but that didn´ t work, because the Web User Control has no namespace (VS.NET didn´t add one).
6
3436
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 { return columns; } set { columns = value; } }
2
2065
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 and the value is a list of MTGTracer. The documentation states:
9
21473
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
9506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10404
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10193
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7525
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5548
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.