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

FileSystemObject

Status
Not open for further replies.

ChrisQuick

Programmer
Oct 4, 1999
144
US
I've seen examples of using the FileSystemObject to reference a file on the server. For example:<br>
<br>
&lt;%<br>
fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>
auto = fs.GetFile(&quot;c:\some.bat&quot;)<br>
Response.Write(auto.size)<br>
%&gt;<br>
<br>
would printout the size of the some.bat file, assuming it existed. If the file did not exist, then you get an error.<br>
<br>
Question:<br>
<br>
How do you conditionally test for the existance of a file after creating your your object?<br>
<br>
Thanks
 
Hi!<br>
You have to use the FileExitst method. It goes like this:<br>
<br>
&lt;%<br>
fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>
if fs.FileExists(&quot;c:\some.bat&quot;) then<br>
auto = fs.GetFile(&quot;c:\some.bat&quot;)<br>
Response.Write(auto.size)<br>
else<br>
Response.Write(&quot;File not found!&quot;)<br>
end if<br>
%&gt;<br>
<br>
Marius Krogh<br>

 
I'm using this in my code<br><br>&lt;%<br>fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>if fs.FileExists(&quot;guests.htm&quot;) then<br>Response.Write(&quot;File found!&quot;)<br>else<br>Response.Write(&quot;File not found!&quot;)<br>end if<br>%&gt;<br><br>and get this error :<br><br>Microsoft VBScript runtime error '800a01b6' <br><br>Object doesn't support this property or method: 'fs' <br><br>/webcor/wedding/password.asp, line 22 <br>
 
I have changed my code to read :<br>&lt;%<br>set fs = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)<br>if fs.FileExists(&quot;guests.htm&quot;) then<br>Response.Write(&quot;File found!&quot;)<br>else<br>Response.Write(&quot;File not found!&quot;)<br>end if<br>%&gt;<br><br>But is says the file is not found, althought I no it does in the same directory.
 
I am not sure about the error since im still trying to learn asp but I think that you have to actualy layout the path I dont think it will let you just use the file name.<br>But if you put like drive:\path\file then it should work that is the only way I have seen the filesystemobject used <p>Steve Hagerman<br><a href=mailto:Admin@Advancedisp.com>Admin@Advancedisp.com</a><br><a href= ISP high speed internet access</a><br>I did it my way!
 
Thanks, that worked, but there must be a way to use relative paths, but at least it works now.
 
Oh but there is but you would have to do a Server.MaPath() for it to resolve the path dynamicaly I am not sure but I think you would put the file name in that ()part <p>Steve Hagerman<br><a href=mailto:Admin@Advancedisp.com>Admin@Advancedisp.com</a><br><a href= ISP high speed internet access</a><br>I did it my way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top