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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for folder. Why doesnt this work? (short)

Status
Not open for further replies.

AlbertAguirre

Programmer
Nov 21, 2001
273
US
Set fs=Server.CreateObject("Scripting.FileSystemObject")

If fs.FolderExists("./images") = true Then
Response.Write("exists")
Else
Response.Write("does not exist")
End If

set fs=nothing


This code always returns false. Why?
 
To get the path to the asp file you can use the following:
request.ServerVariables("APPL_PHYSICAL_PATH")
I am sure there is a better way but here I made loop wich goes back one directory each time:
Response.Write request.ServerVariables(&quot;APPL_PHYSICAL_PATH&quot;) & &quot;<br>&quot;
path = request.ServerVariables(&quot;APPL_PHYSICAL_PATH&quot;)
notroot = true
do while notroot
if instr(1,path,&quot;\&quot;) then
path = mid(path,1,INSTRREV(path,&quot;\&quot;,len(path)-1,vbtextcompare))
Response.Write path & &quot;<br>&quot;
else
notroot = false
end if
loop
 
I'm not trying to get the path to an ASP file. I need to know if that folder (directory) exsists. I then need to loop through the file list i that folder and do some work.

I dont understand why that code I provided above does not work...
 
Albert,

From what I am seeing and from what I know, you need to find the physical path before you check if the folder exists. harmmeijer is pretty much correct. Try to get the physical path, add on the path to the subfolder. Once you get all of that, check to see if it exists. I do not think you can check on a relative path.

Mike
 
The FSO will accept relative paths.

Replace the slash with a backslash:
If fs.FolderExists(&quot;.\images&quot;) = true Then Jon Hawkins
 
I use this and it works just fine:

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

If (Not objfs.FolderExists(Server.MapPath(&quot;.&quot;)& &quot;/x/&quot; & y & &quot;/&quot; & &quot;z&quot;
Then
objfs.CreateFolder (Server.MapPath(&quot;.&quot;) & &quot;/x/&quot; & y & &quot;/&quot; & &quot;z&quot;)
End If
 
Yes I tried it too and it does work. Thanks.
In my previous post I was referring to the backslash message. Simply changing it did not work. I had to create the object as you instructed.

By the way, how do I list specific file in that directory. For instance, if I want to list only files starting with the pattern &quot;t_&quot;?


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top