![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
how can i check if file exist in current directory (in javascript)? |
#3
| |||
| |||
|
|
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...? |


#4
| |||
| |||
|
|
how can i check if file exist in current directory (in javascript)? |
#5
| |||
| |||
|
|
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 |
#6
| |||
| |||
|
|
if("cover.jpg" exist) document.write('<img src='cover.jpg'>') This will not work, since checking whether it exists will be asynchroneous. You will not be able to wait for the result before writing the image tag. |
#7
| |||
| |||
|
|
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? |
#8
| |||
| |||
|
|
[...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)" |
|
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 ps: sorry for my english ![]() |
#9
| ||||
| ||||
|
|
Mark Space <mark_space44 (AT) hotmail (DOT) com> writes: You can only use document.write on the client, so the check must be performed on the client and check the existence of a file on the server. For that, my answer is correct. |
|
If you are talking server side scripting, which is probably ASP then, I would recommend an ASP-specific group, since it is not really about Javascript. |
|
That depends on how the colFolders object is designed. If it is an array, the simple version should work. |
|
/L |

#10
| |||
| |||
|
|
Lasse Reichstein Nielsen wrote: If you are talking server side scripting, which is probably ASP then, I would recommend an ASP-specific group, since it is not really about Javascript. 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.) |
![]() |
| Thread Tools | |
| Display Modes | |
| |