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

check if folder exists

Status
Not open for further replies.

JohannIcon

Programmer
Sep 3, 2002
440
MT
Hi all,

I am trying to upload an image on the server, however if the folder does not exist, it is giving me an error obviusly that the folder does not exist. How can I check if it does?

At the moment I am inserting the image as follows:-

var upLoad = Server.CreateObject( 'w3.upload' );
chosenName = String ( upLoad.Form( 'fileName2' ).item );
file = upLoad.Form( 'theFile' );
if ( file.IsFile )
{
file.SavetoFile(Server.MapPath("\\images\\councillors\\"+chosenName));
%>
The file has been saved as <%= chosenName %>.<BR>
<%
}
%>

Thanks for your help
 
Check out the &quot;folderExists&quot; method from the FileSystemObject. There you can easily check if a given folder exists or not.

Syntax:

var fs;
set fs=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;);
if fs.FolderExists(&quot;myFolder&quot;)=true then
upload the file;
else
show an error message;
end if
set fs=nothing;

I'm not sure about the right JavaScript syntax but I'm pretty sure it's something like this
 
Thanks Stoemp,

it worked, however now I have a problem cause I cannot pass the hidden varaibles to the next page. My code is as follows:-

Set fs=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
If (fs.FolderExists(Server.MapPath(&quot;\images\councillors\&quot;+kunsill)))=false Then
set f=fs.CreateFolder(Server.MapPath(&quot;\images\councillors\&quot;+kunsill))
Response.Write(&quot;Folder Created&quot;)
set f=nothing
set fs=nothing
End If
%>
<input name=&quot;kunsillName&quot; type=&quot;hidden&quot; id=&quot;kunsill&quot; value=&quot;<%=kunsill%>&quot;>
<input name=&quot;kunsillImage&quot; type=&quot;hidden&quot; id=&quot;kunsillImage&quot; value=&quot;<%=Image%>&quot;>
<%
response.Redirect(&quot;kunsillieraInsertPic.asp&quot;)
%>

How can I pass these two hidden parameters to the next page?

Thanks again for your help!

Johann
 
Maybe you can put them in session variables or maybe in the querystring of the page you redirect to however I'm not sure redirect works with querystring variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top