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

(JS) Checking if a folder exists

Explorer ,
Oct 16, 2015 Oct 16, 2015

Hi everyone!

I would like to check if a folder exist. I was trying with this code but doesn't work.

I will thank you in advanced if you know a better way to do this.

Best regards_

- Code not working

path = Folder.desktop + "/MyFiles";

var folder = new Folder(path);

if(!folder.exists){

  alert("Folder doesn't exists");

}else{

  alert("Folder Exist");

}

TOPICS
Scripting
6.5K
Translate
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
Adobe
Participant ,
Oct 16, 2015 Oct 16, 2015

Your code working!

For example:

alert( 'isFolder: ' + Folder('~/Desktop').exists );

Translate
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
Community Expert ,
Oct 17, 2015 Oct 17, 2015
LATEST

Hi Puthoskey‌,

there are some mistakes in your code. Please try something like this:

//path = Folder.desktop + "/MyFiles";     //--------------// declare (var) your variable --> but "path" is IMHO not the best choice for the name of a variable

//var folder = new Folder(path);     //  ?????? what do you want with this ????

var yourFolder = new Folder("~/Desktop/MyFiles");    // I like this syntax more than --> Folder.desktop

if(yourFolder.exists) {

   alert("Folder exists");

   }else{

      alert("Folder doesn't exists");

      }

Have fun

<edited by pixxxel schubser‌>

Translate
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