Skip to main content
dublove
Legend
Jun 23, 2025 4:32 PM UTC
Answered

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

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.

 

 

 

m1b
m1bCorrect answer
Community Expert
Jun 24, 2025 3:04 AM UTC

@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

12 replies

Community Expert
Jun 23, 2025 4:48 PM UTC

One thing you can do sort of brute force is

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

-Manan

Translate
-Manan
dublove
dubloveAuthor
Legend
Jun 23, 2025 4:59 PM UTC

HI Manan Joshi

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

Translate
Community Expert
Jun 23, 2025 5:03 PM UTC

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

Translate
-Manan
Community Expert
Jun 23, 2025 4:43 PM UTC

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

Translate
-Manan
dublove
dubloveAuthor
Legend
Jun 23, 2025 4:50 PM UTC

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.

Translate