Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP!.. FileSystemObject problem :-( 1

Status
Not open for further replies.

dbrom

Programmer
Feb 21, 2001
100
US
Hi everybody,

I have this weired problem with FileSystemObject.
It does not seem to let me access the File objects in
Files collection. I am sure there are files in the folder,
and I have tried it on several folders.
As you can see I am using Javascript,
and here is the bit of my code.

.....................

strFullPath = Request.ServerVariables("APPL_PHYSICAL_PATH");

objFso = Server.CreateObject("Scripting.FileSystemObject");

objFolder = objFso.GetFolder(strFullPath);

objFiles = objFolder.Files;

for (objFile in objFiles)
{
Response.Write(objFile.Name); //Does not write anything back to client
}

......................

Hope you can help.
<Dmitriy>
dbrom@crosswinds.net
 
What is the error that it gives

it might have some thing to do with permissions

regards Unicorn11
unicorn11@mailcity.com

[red]Luck is not chance, it's toil; fortune's expensive
smile is earned.[red]
 
I don't think that this is the problem...
Any other ideas?
<Dmitriy>
dbrom@crosswinds.net
 
Looks like you have your syntax all mixed up -- So I'm guessing that isn't copied and pasted from your file. Try this:

for each file in objFolder.files
Response.Write(file.Name)
next

penny.gif
penny.gif
 
link9,

the code that you supplied is for VBScript,
but I am writing in Javascript.

The weired thing is, this Javascript code does not work.


var objFso, objFolder, objFiles, strFullPath;
var objFile = new Object;
strFullPath = Request.ServerVariables(&quot;APPL_PHYSICAL_PATH&quot;);


objFso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;);

objFolder = objFso.GetFolder(strFullPath);

objFiles = objFolder.Files;

for (objFile in objFiles)
{
Response.Write(objFile.Name);
}



However, the following VBScript code works (?!!)



Dim objFso, objFolder, objFiles, objFile, strFullPath

Set strFullPath = Request.ServerVariables(&quot;APPL_PHYSICAL_PATH&quot;)

Set objFso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)

Set objFolder = objFso.GetFolder(strFullPath)

Set objFiles = objFolder.Files

For Each objFile In objFiles
Response.Write(objFile.Name & &quot;<BR>&quot;)
Next


I don't get it - why for .. in cycle in Javascript does not work (????)
<Dmitriy>
dbrom@crosswinds.net
 
for (objFile in objFiles)
{
Response.Write(objFile.Name);
}

does not look to me like a valid javascript statement -- a for loop in javascript must have an counter, a condition, and an incrementer --

for (objFile; objFile <= objFiles.count; objFile ++){
counter condition incrementer
}

Something along those lines, but I'm sure that won't work as is. But you have to have those three elements.
penny.gif
penny.gif
 
You are 90% correct link 9.

JScript v5 does however support for ( object in array ) syntax.

The problem is probably that the Javascript version that you are running is older and doesn't support that syntax.
(get a newer one at
Otherwise do:
for (i=0;i<objFile.files.count;i++)
{ response.write(objFile.files.name);
}
 
I got it (!!!)
Thanks to all of you.
Looks weired but it works.
I found the solution in my ASP book.


var objFiles = new Enumerator(objFolder.Files);

for (; !objFiles.atEnd(); objFiles.moveNext())
{
objFile = objFiles.item();
Response.Write(objFile.Name);
}


So there it is, in case anybody needs it in the future.
Thanks again. :)
<Dmitriy>
dbrom@crosswinds.net
 
That works..

You could also do:

while (!objFiles.atEnd())
{ response.write(objFiles.name + '<BR>');
objFiles.moveNext();
}
 
Thanks Swany.
:) <Dmitriy>
dbrom@crosswinds.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top