How the test of a directory?

How to test if a path to a directory instead of a file?

File (path) .exists () new seems to return true in both cases.

I found myself new file (path) .length =-1, because the directories seem to have a length of-1 as reported by the InDesign scripting DOM but I don't have really a lot of confidence that it is either portable or reliable in the future. Is there a better way?

I guess I could try to create a file in the directory, but I don't like not to change the file system, and the script may not have permission to do so anyway. It's JavaScript, so it's hard to pay for a program (like ls - l) external, and that would really kludgey anyway.

The slashes do not affect the. exists().

the file manufacturer allegedly returns a Folder object in this case, but. constructor.name is always file.

What is recommended? Thank you!

If I understand the question, initially, all we have is a path string, and the decision is to know if create a file or folder from that object. Of course, then compares instanceof or constructor.name is questionable.

A similar length is-1 observation would be the property of File.type, which is not defined for the records.

Have a look in the JavaScript Tools Guide gives the best approach, though.

"If the path refers to an existing folder:

The file function returns a folder instead of a file object object.

The new operator returns an object of a non-existent file with the same name file. »

So - simply omit the 'new' and the types of tests, such as discussed.

Dirk

Tags: InDesign

Similar Questions

  • How to test if a directory is empty

    I have to test if a directory is empty or not.
    How can I do it in a simple way?
    Thank you

    OdiFileWait use tool in a package
    and 'Répertoire' and 'File name mask' property to check if a directory is empty or not.
    There is another property "error if no file found". This can be used for a condition of KO to check if the directory is empty.

  • Test Oracle Internet Directory Connector for IOM

    Hello

    I'm testing the running test cases available in the Oracle Internet Directory Connector for IOM, but I'm not because it seems that the current version of this connector does not have the java class tcUtilTestOID as described in the documentation. This class should be at the level of the test\troubleshoot\scripts directory, but there are only files of orders with test cases.

    Can anyone confirm this or give me this class file?

    Thanks in advance.

    This is the code. Include in your jar file personalized with the same name. You will be done I guess:

    import com.thortech.util.logging.Logger;
    import com.thortech.xl.integration.OID.util.tcUtilLDAPOperations;
    import java. IO;
    import java.util.Properties;
    Import javax.naming.directory.BasicAttribute;
    Import javax.naming.directory.BasicAttributes;

    public class tcUtilTestOID
    {

    private static String CONFIG_FILEPATH = "global.properties."

    public tcUtilTestOID()
    {
    }

    Public Shared Sub main (string args [])
    {
    tcUtilLDAPOperations ldapOp = null;
    Logger logger = Logger.getLogger ("TEST_USER_PROVISION");
    logger.info("**********************************");
    Logger.info ("*" + args [0]);
    Try
    {
    FileInputStream file = null;
    Try
    {
    ConfigFile = new FileInputStream (CONFIG_FILEPATH);
    }
    catch (FileNotFoundException fe)
    {
    Logger.Error ("could not find the configuration file (" + CONFIG_FILEPATH + "" ")" ");
    fe.printStackTrace ();
    }
    Prp properties = new Properties ();
    Try
    {
    PRP. Load ("ConfigFile");
    }
    catch (IOException IE)
    {
    Logger.Error ("unable to load the configuration file (" + CONFIG_FILEPATH + "" ")" ");
    ie.printStackTrace ();
    }
    String serverName = prp.getProperty ("serverName");
    String portNo = prp.getProperty ("portNo");
    String rootContext = prp.getProperty ("rootContext");
    String principalDN = prp.getProperty ("principalDN");
    String principalPass = prp.getProperty ("principalPassword");
    Boolean sslFlag = "true".equalsIgnoreCase (prp.getProperty ("sslFlag"));
    Logger.info ("the server name =" + serverName);
    Logger.info ("portNo =" + portNo);
    Logger.info ("rootContext =" + rootContext);
    Logger.info ("principalDN =" + principalDN);
    Logger.info ("sslFlag =" + sslFlag);
    Logger.info("===\n");
    ldapOp = new tcUtilLDAPOperations (serverName portNo, rootContext, principalDN, principalPass, sslFlag);
    String ldapUserDNPrefix = "cn".
    String ldapObjectClass = "objectclass";
    String ldapUserObjectClass = "inetOrgPerson";
    String ldapFirstName = "givenName";
    String ldapLastName = "sn."
    String ldapCommonName = "cn".
    String ldapPassword = 'userPassword ';
    String containerDN = prp.getProperty ("containerDN");
    Logger.info ("containerDN =" + containerDN);
    Logger.info ("UserOperation selected =" + args [0]);
    If (args [0] .equalsIgnoreCase ("createUser"))
    {
    Logger.info ("CREATE USER CALLED");
    String createUserFName = prp.getProperty ("createUser.firstName");
    String createUserLName = prp.getProperty ("createUser.lastName");
    String createUserUserDN = prp.getProperty ("createUser.userDN");
    String createUserUserPass = prp.getProperty ("createUser.userPassword");
    Logger.info ("createUser.firstName =" + createUserFName);
    Logger.info ("createUser.lastName =" + createUserLName);
    Logger.info ("createUser.userDN =" + createUserUserDN);
    Logger.info ("createUser.userPassword =" + createUserUserPass + "\n\n");
    BasicAttributes basicattributes = new BasicAttributes (true);
    BasicAttributes.put (new BasicAttribute (ldapObjectClass, ldapUserObjectClass));
    BasicAttributes.put (new BasicAttribute (ldapFirstName, createUserFName));
    BasicAttributes.put (new BasicAttribute (ldapLastName, createUserLName));
    BasicAttributes.put (new BasicAttribute (ldapCommonName, createUserFName + "" + createUserLName));
    BasicAttributes.put (new BasicAttribute (ldapPassword, createUserUserPass));
    ldapOp.connectToLDAP ();
    userCreated Boolean = ldapOp.createObject (ldapUserDNPrefix + "=" + createUserUserDN + "," + containerDN, basicattributes);
    ldapOp.disconnectFromLDAP ();
    If (userCreated)
    {
    Logger.info ("\t >" + createUserUserDN + "-USER_CREATION_SUCCESSFUL");
    } else
    {
    Logger.info ("\t >" + createUserUserDN + "-USER_CREATION_FAILED");
    }
    } else
    if(args[0].) Equals ("ModifyUser"))
    {
    Logger.info ("EDIT USER CALLED");
    String modifyUserUserDN = prp.getProperty ("modifyUser.userDN");
    String modifyUserParamName = prp.getProperty ("modifyUser.paramName");
    String modifyUserParamValue = prp.getProperty ("modifyUser.paramValue");
    Logger.info ("modifyUser.userDN =" + modifyUserUserDN);
    Logger.info ("modifyUser.paramName =" + modifyUserParamName);
    Logger.info ("modifyUser.paramValue =" + modifyUserParamValue);
    ldapOp.connectToLDAP ();
    BasicAttributes basicattributes = new BasicAttributes (true);
    BasicAttributes.put (new BasicAttribute (modifyUserParamName, modifyUserParamValue));
    Boolean isUserModified = ldapOp.modifyAttributesReplace (ldapUserDNPrefix + "=" + modifyUserUserDN + "," + containerDN, basicattributes);
    ldapOp.disconnectFromLDAP ();
    If (isUserModified)
    {
    Logger.info ("\t >" + modifyUserUserDN + "-USER_UPDATE_SUCCESSFUL");
    } else
    {
    Logger.info ("\t >" + modifyUserUserDN + "-USER_UPDATE_FAILED");
    }
    } else
    if(args[0].) Equals ("deleteUser"))
    {
    Logger.info ("DELETE USER CALLED");
    String deleteUserUserDN = prp.getProperty ("deleteUser.userDN");
    Logger.info ("deleteUser.userDN =" + deleteUserUserDN);
    ldapOp.connectToLDAP ();
    Boolean isUserDeleted = ldapOp.deleteObject (ldapUserDNPrefix + "=" + deleteUserUserDN + "," + containerDN);
    ldapOp.disconnectFromLDAP ();
    If (isUserDeleted)
    {
    Logger.info ("\t >" + deleteUserUserDN + "-USER_DELETION_SUCCESSFUL");
    } else
    {
    Logger.info ("\t >" + deleteUserUserDN + "-USER_DELETION_FAILED");
    }
    }
    }
    catch (Exception e1)
    {
    E1. PrintStackTrace();
    return;
    }
    }

    }

    Thank you

    Sunny

  • How to test moduleDeletionsPending, in the Simulator, I don't have the option to remove my application

    How to test the following?

    I want to test the functionality by using the method public void moduleDeletionsPending (String [] moduleNames). I had written logic that removes files from an SD card and it works when I call a menu inside my application item.

    However, it should only be run when I uninstall the application.

    In 9700 Simulator, if I select Options > Applications > [highlight the application] > [open the menu by pressing the Insert key on my keyboard] - I don't see the option to remove the application.

    I don't see the delete option for other applications, such as the Klondike card game.

    Should I set a property or the permissions of my app should be deleted in a simulator, so I can test the moduleDeletionsPending method?

    Thank you.

    You will need to 'install' the app in the BlackBerry smartphone Simulator so that your application appear in the list of applications.  You won't see here when you perform an execution/debug as, when you use the file, the option of loading or copy it into the directory of Simulator.

    The following link explains the different ways to install an application.

    How to deploy and distribute Applications

    http://supportforums.BlackBerry.com/T5/testing-and-deployment/how-to-deploy-and-distribute-Applicati...

    Note that you can install using a simulated so USB connection.  Click on the menu of the smartphone Simulator simulation BlackBerry and check USB cable connected.  Note that you can not the debugger attached when installing via a simulated USB connection.

  • How can I get the properties of a directory, IE

    I have an Imac w El Capitan - and the Windows user.  How can I get the PROPERTIES of a directory.  (number of files, size and type)

    slimhorn wrote:

    I have an Imac w El Capitan - and the Windows user.  How can I get the PROPERTIES of a directory.  (number of files, size and type)

    Can you do a right click on the folder and choose "Get Info"?  That will tell you how many files is in it, how big is the file, etc.

  • How to test the USB on Satellite Pro C870 speed?

    Hello

    Please I have connect WD item 10 B 8 USB drive to plug 750Go BLUE.
    Please how can test if USB3 uses full speed or lower connection USB2 bus?
    Brand of disk Crystal 3.03 said 31 MB/s reading and writing! (too low for USB3!)

    Thank you

    Hello

    You can use some freeware like tools
    -H2testw
    -Drive the speed Test 3.2
    I used the H2testw to SD card check and test USB memory stick and I was satisfied.

  • How can I keep my HP1510 all-in-one to print the test pages as much?

    How can I keep my HP1510 all-in-one to print the test pages as much? My printer is connected to my laptop, and it seems that whenever I disconnect, want the printer print a test page when I reboot. I don't know where the option is to disable this option.

    Pages are likely alignment pages.  When a new cartrdige is installed the printer will print an alignment page which should be placed on the scanner glass and press the button of scan to complete the alignment process.  If the alignment is not complete it will repeat when the printer is powered suite or maybe at the end of print jobs.

    The alignment page will stop printing when the alignment process is complete.  See the page here for more information.

  • How to test the audio and the video on Android

    How to test audio and video on Android?

    How it is checked when installing Skype on Android?

    What I'm asking, is available in the desktop version to Tools-> Options-> Audio settings, and Tools-> Options-> video settings. And is checked during the installation of Skype for desktop PC as Configure Skype / check your audio and video files.

    (Of course I searched the whole Skype app and found no.) I have the echo service by my microphone is weak, I am lost.)

    Thank you.

    Sign in to your ID on Skype desktop and call your android phone to test

    It's something is broken, there is not that you can do, other than downgrading to an older version. There are also a couple of settings to activate the camera and photo qualityin settings in some versions.

  • How can I include results of a subsequence, which takes place in a new thread in the test report from the main sequence

    Hello!

    I have ", working with the Version 4.2.1 of TestStand. I have a main sequence, which sous-séquences of different calkls. All these steps are reported correctly. One of the subsequences works like "new thread". How can I include his results in the common test report of the main sequence?

    I have variable markes of the subsequence as is required for the test report (it works OK if it's not a new thread). If the digital test, which is performed in this subsequence is correct, I get no results at all. If the digital test could not get a "message in red" who whithout having failed to test any reference to step somewhere in the report of the main sequence or values of vaiables that were not correct.

    I tried an option 'on the fly' in the Configuration of the report, but n ' got no useful result. What should I do?

    Best regards

    Hello Pericles,

    You can use a queue time for the results of the wire once it ends. Place a waiting time after the call to the thread in your MainSequence at the location where you want the results to add to the report (compared to other results). In the waiting step Setup tab, select wait: Thread the threaded sequence, and then select call to specify sequence call the radio button. You can also use an object reference if you need results if poster somewhere where elsewhere - you would just add an object reference to the appeal of sequence threaded in its thread settings dialog box.

    I hope this helps.

    -Jack

  • How to test if the pc is connected to the TCP/IP protocol?

    Hello

    I have a VI how should the data received from another PC, using a TCP/IP connection.

    My VI could connect, receive data, but if I lose the connection im not able to reconnect, because I do not know how to test if my pc is connected to the other.

    Thank you for your help,

    Best regards

    salim_mjs wrote:

    Hey,.

    I was checking for error 66, I think that it check if the connection has been closed in order to reconnect

    do you not think that the error 56 or 60 are better?

    with respect,

    56 is the time-out. This will depend on your remote service if this should be considered as error or ignored. If it is a server application, it should certainly be able to respond within the time limit. But if your host application is the server and the remote application is the client it is very common to receive a time-out error when querying the client if it has new data to send.

    Order the examples mentioned previously, they really give you a good idea on how TCP/IP network communication must all work, even if there is still a lot to improve to create a truly reliable connection. But start from there come back if you get into trouble.

    Rolf Kalbermatter

  • How to test the domain controller security policy works or not?

    How to test the domain controller security policy works or not?

    So far, I put a security policy in the domain controller security policy, however, I do not affect client computers joined to the domain controller. and so far, if I apply the domain security policy work.

    LiuAlex

    Server must wonder about the Technet site.  http://social.technet.Microsoft.com/forums/en-us/home

  • I need to know how to disable the test print cause everytime I turn on the printer prints featured.

    I need to know how to disable the test print cause everytime I turn on the printer prints featured.  It is hp1315 series.

    Hello

    If you want to disable printing test page, you must check with the manual of the printer. Try the steps from the following link:

    An alignment Page prints whenever the all-in-one is turned on or off or a print job is started
    http://h10025.www1.HP.com/ewfrf/wc/document?DocName=c01336397&cc=us&DLC=en&LC=en&product=1146336&tmp_track_link=ot_search

    I suggest you to contact HP for better support.
    http://h30434.www3.HP.com/T5/printer-all-in-one-software/BD-p/software

    Additional information:
    http://h20000.www2.HP.com/bizsupport/TechSupport/document.jsp?objectID=c01577197&lang=en&cc=us&ContentType=SupportFAQ&prodSeriesId=360489&prodTypeId=18972

    Printer in Windows problems
    http://Windows.Microsoft.com/en-us/Windows/help/printer-problems-in-Windows

  • How to test the object lost focus?

    How that test an object lost focus?

    Van you listen to the accent of the event

  • How can I save a directory or a specific file without saving the Image to the system?

    Purchased new software my company insists on the fact that we back up software data every day on a USB. I tried to schedule a backup, but I don't want the Image of the backup system. How can I save a directory or a specific file without saving the Image to the system?

    When you choose what to back up, simply uncheck the box of system image:

    Or another simple way is to program a command that copies the files on your USB key, replacing the backup from the night before.

    For example, this command copies all of my 'Project X' folder on my USB drive (drive E :)

    copy 'c:\project x\' e:

  • How to test the backlight of the Simulator

    Hello Guyz

    Im kind again in the development of blackberry so its more than a new hobby as I recently an interest in java.  So my first app is an attempt to make an application which the camera back given the fon. so I would like to know how to test, without the need to put it on my son, how do I know if d backlight is turned on or off, is the way to display the interface back to the Simulator or something. I'm using eclipse and the blackberry 9800 torch Simulator. How to test the light from my pc?

    Thanks for your time, im hoping a response. Take advantage of the UL

    You can't test the flash of the camera in the BlackBerry smartphone Simulator.  You will need to test this on a real Smartphone BlackBerry.

Maybe you are looking for