Skip navigation
Currently Being Moderated

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

Mar 29, 2013 6:13 AM

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

 
Replies
  • Currently Being Moderated
    Mar 29, 2013 12:01 PM   in reply to 4everJang

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 3, 2013 1:49 AM   in reply to frameexpert

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points