Skip to main content
dublove
Legend
June 23, 2025
Answered

How can I determine if an image really exists by a certain address?

  • June 23, 2025
  • 2 replies
  • 599 views

For example, the following code:

mynewLink=decodeURI(lst[p]);
alert(mynewLink);

The output is:

file:C:/Users/dublove/Desktop/PDF/6688.PSD

How does this determine if 6688.PSD really exists?

if(mynewLink.exists){
....
}

This doesn't seem right.

Thank you.

 

 

 

Correct answer m1b

@dublove Just to further elaborate on what Manan is doing...

 

(1) using the substring method to change this string

file:C:/Users/dublove/Desktop/PDF/6688.PSD

 into this string

/Users/dublove/Desktop/PDF/6688.PSD

 

 (2) creating a File object, like this:

var myFile = File('/Users/dublove/Desktop/PDF/6688.PSD')

 

(3) checking if exists 

if (myFile.exists)
    ...

 

It must be a File object because `exists` is a method property of File (and Folder).

- Mark

2 replies

Community Expert
June 23, 2025

One thing you can do sort of brute force is

if(File(mynewLink.substring(mynewLink.indexOf("/"))).exists)

-Manan

-Manan
dublove
dubloveAuthor
Legend
June 23, 2025

HI Manan Joshi

I Can't see the principle, but this surprisingly works for me.
Thank you very much.

Community Expert
June 23, 2025

What I did was create a valid path from the URI by removing the file: from it. Using this path I created a File object and then used this objects exists property

-Manan

-Manan
Community Expert
June 23, 2025

What is lst[p]. The idea is to get a file object and then use the exists method on it to check if the file exists or not

-Manan

-Manan
dublove
dubloveAuthor
Legend
June 23, 2025

lst[p] is taken from the dropdown list.
I want to relink d:\aa\a.jpg
to d:\aa\a.tif
So, need to determine if a.tif exists first.