Z
zhisol
how can i check if file exist in current directory (in javascript)?
how can i check if file exist in current directory (in javascript)?
This isn't really possible with normal JS in a normal security
environment.
Did you mean on the server or on the client?
Is this for a web page or an intranet application, CD-ROM, etc...?
how can i check if file exist in current directory (in javascript)?
zhisol said:if("cover.jpg" exist)
document.write('<img src='cover.jpg'>')
else
//display nothing
and i don't know how can i realise "if("cover.jpg" exist)"
for example i have address: http://mysite.com/show.html
and if in root on server is a file "cover.jpg", make this visable,
otherwise not.
normally in html if "cover.jpg" doesn't exist - client see empty box, but
i want that he'll see nothing
Mark Space said:Huh? As it happens, I was going to ask almost exactly the same
question. Your answer makes no sense to me. I mean, in vbscript I
can read files, directories, etc. But it doesn't work in JavaScript?
Wow. You don't mean client side vs. server side, do you?
In vbscript I can do something like this:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
pathXlat = Request.ServerVariables("PATH_TRANSLATED")
pathXlatRoot = Left( pathXlat, InStrRev( pathXlat, "\" ) )
Response.Write "My Path: " & pathXlatRoot & "index.html <br>"
and the path shows up just fine. I can also step through the files or
folders in my subdirectory like so:
Set objFolder = objFSO.GetFolder( pathXlatRoot )
Set colFolders = objFolder.SubFolders
For Each objSubFolder in colFolders
If FileExists( objSubFolder, "a_name" ) Then
call do_something()
End If
Next
No problemo. Anyone know the javascript equivalent?
zhisol said:[...snip...]
it's for web page. i mean exactly that:
if("cover.jpg" exist)
document.write('<img src='cover.jpg'>')
else
//display nothing
and i don't know how can i realise "if("cover.jpg" exist)"
Mark said:That was actually my next question. Which is better for server side
scripting, VBScript or Javascript? It seemed to me that Javascript
actually had more standards that recognized it, and I wondered if it was
more popular than MS only VBScript. I've only done VBScript so far.
(CGI like Perl or PHP really aren't an option for this project.)
Send a HEAD request for the "cover.jpg" file. In the handler that is
triggered when the response comes back, check for 200 response code &
then make the image visible at that point.
it seems, this web page doesn't exist
zhisol said:<script language="JavaScript">
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("HEAD", "cover.jpg", false);
xmlHttp.send();
document.write(xmlHttp.statusText);
</script>
is that correct to see return code on the browser screen?
i see nothing
zhisol said:<script language="JavaScript">
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("HEAD", "cover.jpg", false);
xmlHttp.send();
document.write(xmlHttp.statusText);
</script>
is that correct to see return code on the browser screen?
i see nothing
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.