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

Check if file exists in javascript without using ActiveX

Status
Not open for further replies.

mmed

Programmer
Jan 20, 2009
1
EG
I'm new to this forum. I'm trying to use javascript to check if file exists on local hard disk without using ActiveX object(FileSystemObject). I tried to use the File object but I get the error: 'File' undefined Object using internet explorer 7.0.

<html><head>
<script language="javascript">
function CheckFile()
{
f = new File("c:\\user.txt")
if (f.exists)
{
alert("File exists");
}
else
{
alert("File Does not exist");
}
}

</script>
</head>
<body onLoad="CheckFile()">

</body>
</html>

thanks

 
Hello,
I think the issue is that there is a security problem when dealing with this.
I tried the following code on my server and it kept returning FALSE:
Code:
 <!--
function CheckFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
FileExist = fso.FileExists("TEST.txt");
if (FileExist == true){
 alert("True")
 }
 else
{
 alert("FAIL");
 }
} 
-->
I know it does not solve the issue but may help.
I will keep trying to figure this out.
 
You might be able to script it, but doing it without the FSO (IE) or Java file IO call (Fx, etc), I'm not sure you'll manage it.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top