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

How to know if an object is a File or a Folder ?

Advocate ,
Mar 29, 2013 Mar 29, 2013

Copy link to clipboard

Copied

Hello again,

I am looking for an easy method to determine whether a File or Folder object point to an actual file or to a folder. Both objects seem to have the same set of properties, except the File element has more. But the Data Browser in the ESTK refuses to show the contents of a File object when I have not actively retrieved the properties yet. Is this simply a matter of testing whether a file-related property exists in the object? Is there another, more elegant method, an undocumented feature, for instance a property IsFolder or something similar ?

Ciao

Jang

TOPICS
Scripting

Views

846

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
Community Expert ,
Mar 29, 2013 Mar 29, 2013

Copy link to clipboard

Copied

Hi Jang,

This from Chapter 3 of the JavaScript Tools Guide:

There are several ways to distinguish between a File and a Folder object. For example:

if (f instanceof File) ...

if (typeof f.open == "undefined") ...// Folders do not open

File and Folder objects can be used anywhere that a path name is required, such as in properties and arguments for files and folders.

Rick

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
Community Beginner ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

LATEST

If you simply want to check, if the file/folder object you created points to a file/folder on your computer, maybe this might work:

if (File.exists) ...

or

if (Folder.exists) ...

Jürgen

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