• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Check if certain files exist

New Here ,
May 28, 2006 May 28, 2006

Copy link to clipboard

Copied

Hi all,

I am writing a reference guide and wondering if I can check whether some files exist from a page.
If it exists then I can forward the user to one page.
And if not they will see another page.
Grateful if someone points me to the right direction.

Thanks,
Karen

Views

247

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
May 30, 2006 May 30, 2006
Hello Cognethos,

You need to use double backslashes in your file path reference. Your script is correct except this line:
if(fso.FileExists("C:\Program Files\Common Files\My Directory\My file.txt"))

It should read this:
if(fso.FileExists("C:\\Program Files\\Common Files\\My Directory\\My file.txt"))

The technical reason for this is that there are special characters that you can not directly use in a string. In this case, your path is the string. Backslash happens to be one of the special char...

Votes

Translate

Translate
New Here ,
May 28, 2006 May 28, 2006

Copy link to clipboard

Copied

Hi all,

Further investigating to it, I tried the following:

<script language=JavaScript
type="text/javascript">var fso = new ActiveXObject("Scripting.FileSystemObject");

if(fso.FileExists("C:\Program Files\Common Files\My Directory\My file.txt"))
{
document.write("File Exist");
}
else
{
document.write("File not exist.");
}</script>

I always get "File not exist" message but I don't know why.
Can anyone know where it is wrong?

Thanks,
Karen

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 30, 2006 May 30, 2006

Copy link to clipboard

Copied

LATEST
Hello Cognethos,

You need to use double backslashes in your file path reference. Your script is correct except this line:
if(fso.FileExists("C:\Program Files\Common Files\My Directory\My file.txt"))

It should read this:
if(fso.FileExists("C:\\Program Files\\Common Files\\My Directory\\My file.txt"))

The technical reason for this is that there are special characters that you can not directly use in a string. In this case, your path is the string. Backslash happens to be one of the special characters that you can not directly use in a string. To get around this, you need to do something called an escape sequence. In this case, the escape sequence for \ is \\.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
RoboHelp Documentation
Download Adobe RoboHelp