Prevent missing file/object from stopping code.

How do I prevent assigning of an object that doesn't exist to a variable from stopping the script?  For example, I want to assign the application 800x600.psd to a variable, if it's open, so that the program can make use of it, but if it's not open, I don't want the script to stop on the error that it could not find it.  The code I use to assign this file to a variable is:
var theScaledDoc = app.documents.getByName("800x600.psd");
But if I run this without that file currently open in Photoshop, it stops the script with the error "No such element".  How do I bypass this error if the file is not open, yet assign it if it is open?
Thanks for any help!
dgolberg

You could trap the error and open the file if required ie:-
function main(){
try{
   var theScaledDoc = app.documents.getByName("800x600.psd");
   }catch(e){
       if (confirm('The file is not open. Would you like to open it?')) {
           var theScaledDoc = File.openDialog("Please select Image","*.*");
           open(theScaledDoc );
           }else{
               return;
main();

Similar Messages

  • How to get File  object from Document Object . ?

    In conventional Dom Parsing we pass file to DocumentBuilder to get Document Object .
      File file = new File("c:\\MyXMLFile.xml");
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(file); // gOT Document here . My problem is how do i get File object back from Document . If i have Document object with mi.
    Please consider above code as example i dont have File object in my code . i am using Xhive DB API where i get Document directly from API method .
    I need to convert this Document to File to get size of file
    Please suggest solution on this
    Edited by: AmitChalwade123456 on Dec 5, 2008 6:10 AM

    Hello Guys any views on this topic

  • How to create File object from InputStream

    Hi everybody
    Can I know a way to create a File object from InputStream object
    Here's my code:
    URL url = loader.getResource(xsdFile); //Thats a schema file..not to worry
    InputStream istream = url.openStream();
    Now from that 'istream' I need to build File object.
    Thank you all

    didn't know fileinputstream was made to read url objects ; in the doc, it just says "A FileInputStream obtains input bytes from a file in a file system." ; according to me, website is something outside the filesystem, but i could be wrong
    edit: thought from the beginning it was all about FILEinputstream whereas it just says "inputstream" in the post ; my bad, it's still early in the morning here X)

  • Create File Object from a remote file

    Hi,
    I would like to know about how to create a new File object from a file in a remote machine, it is a web application, i have the remote route of the file, and if I need the ip of the remote machine, I would like to know how to get it too.
    File fileobject = new File(�What do I have to put here or before or whatever?);
    Thank you very much.
    J.

    First, from the technical point of view you can't create a File object unless it's a file on the computer where the code is running. It doesn't matter if you have an IP address or something, if you haven't mapped a drive to it you can't create a File object.
    But more importantly, you can't just reach out from your server and grab a file from the client's computer. That's an obvious security violation and if you didn't realize that you shouldn't be designing web applications yet. If you want a file uploaded then you have to provide the client with an HTML form where they select a file to be uploaded.

  • Creating File objects from all files in a folder.

    Hi, I'm not too brilliant of a programmer, so this may be an obvious one that I could find in the API.
    My goal is to compare files for similarities and then give some output, that's not too important.
    My question is: How do I create an array of File objects from a folder of *.txt files, without creating each individually? Is there a way to simply get all the files from the folder?
    File I/O is still pretty new to me. If I didn't give a good enough explanation, please say so.
    Thank you very much!

    Note by the way that a File represents an abstract pathname, the idea of a file as a location. It doesn't specify the file's contents, nor does it require that the file it represents actually exists. A better name might be "theoretical file" or "directory listing entry".
    So getting a whole bunch of File objects is itself perhaps not necessary (although it could be useful).
    To expand on reply #1, look for File methods whose names start with "list".

  • Access file object from flex web app

    Hi all,
    I want to access file object from flex web app. What should i do?
    I have to take array from my XML. In XML there will be only dir path. So for taking file name from dir i have to access it and have to perform for loop on that dir.
    What should I do?
    Any Ideas?
    Thanks,
    -CK

    Hi Michael
    My question is that I dont want to give name of images in XML file.
    In XML file there will be only path of image directory. So I need to find all image name from that image directory.
    Thats why I want to access file object.
    Any ideas?    

  • Preventing certain file types from being displayed in a directory listing

    Someone before me used this code to create simple directory
    listings for our
    users to maintain certain sections of the site...
    http://www.asp101.com/samples/viewasp.asp?file=dir_list.asp
    My question is, can some additional code be added or change
    to prevent
    certain files from showing up in the list.. like the
    default.asp and so
    on...
    ASP, SQL2005, DW8 VBScript

    Just test the string value of the filename in the output loop
    and skip it if it meets the criteria you want to filter out.

  • Can u access Oracle9i Reports objects from Java Code?

    Hi,
    How can you access Oracle9i Reports (Rel 2) objects like Body, DataSource, Groups etc from Java Code?
    What are the available APIs?
    I went thru the APIs at http://otn.oracle.com/products/reports/htdocs/getstart/docs/Javadocs/oracle/reports/plugin/definition/package-summary.html
    However various constructors stated in these APIs are using classes from "oracle.reports.definition" package which are difficult for me to locate.
    For eg. Report constructor is using oracle.reports.definition.RWReport and there is no API documentation available for RWReport class.
    Please suggest me the site for the above APIs or the method to get a reference to "Report" instance.
    Thanks
    Rakesh.

    Thanks Tugdual for your quick reply.
    Thats exactly what I am trying to do. I want to develop a utility which can have a subset of Report Developer's functionality.
    Currently using Reports Developer & Report Wizard, I can create a report by providing SQL statement and few parameters (like Report Style, Calculated Fields, Template file etc). I want to put all these parameters in a XML file and run my java utility (based on the APIs which I am looking for) which will use these XML parameter file and generate a '.rdf' file.
    Also, could you please suggest me the site for oracle.reports.definition package API or the way to get a reference to oracle.reports.plugin.definition.Report instance.
    Thanks,
    Rakesh

  • Create a File object from a file in a .jar

    i looked for 2 hours...
    i tired this:
    URL url =  MyClass.class.getResource("filename.dat");
    File file = new File(url.getFile());i give up.

    The problem is that the file inside a Jar file is not
    a file. The jar file just contains a stream of bytes
    in the format needed to make the Jar file. Jar files
    are not folders like in the directory. So to get at
    the contents of the Jar file you need to read the Jar.
    The getResource method returns the URL which is a
    file URL, but this only works because Java has
    handlers that deal with getting the contents from a
    Jar file based on this type of URL. A URL cannot
    just be made into a file. I'm not sure that the File
    object can handle this type of file URL (I guess not
    or we wouldn't be having this discussion). So really
    it just depends what you want do. If you want to
    extract the file, just read the data in from the
    inputstream gotten from the URL, or better just call
    getResourceAsStream(), and read the bytes into an
    array. After this, you can do whatever, write it as
    a file to the hard drive, convert to a string, get
    the size based on the array length. makes sense, but how could i get an InputStream into an array, dont i need the size of the array first? and i dont think i can use InputStream.available()to figure it out... i tired downcasting to a FileInputStream yet no avail.

  • Create file object from xml file in different package

    I have my java class which is in a package...edu.xx.proj
    It contains the following
    File f = new File("formats.xml");
    My xml file is in the package edu.xx.proj.xml
    How do I get the file object for my xml file?
    Ultimately I want that once the jar is shipped .. The path of xml file shld be independent of my OS path... it can only lookup the package path..
    I will really appreciate it if someone can throw some input as to how to resolve this issue..
    Thank you

    I have my java class which is in a
    package...edu.xx.proj
    It contains the following
    File f = new File("formats.xml");
    My xml file is in the package edu.xx.proj.xml
    How do I get the file object for my xml file?
    Ultimately I want that once the jar is shipped .. The
    path of xml file shld be independent of my OS path...
    it can only lookup the package path..
    I will really appreciate it if someone can throw some
    input as to how to resolve this issue..
    Thank you
    InputStream inputStream = getClass().getResourceAsStream("xml/formats.xml");
    /* OR */
    URL url = getClass().getResource("xml/formats.xml");hth

  • Getting uploded file object from bea Content repository

    Hi,
    This is regarding bea portal 8.1 content repository
    I have a content node ,type of content is message or article
    Now in this one of the attribute is Attachment..
    I have uploded a XMl file to this attribute
    How do i retrive this file object using bea cutom tags,,
    Are there any custom tag available? or
    can i accessthis document using some kind of API..?
    Can anyone please throw light on this...
    Quick response will be highly appreciated
    Thanx a lot
    Manish Rathi

    Manish,
    You can use the GetPropertyTag located in com.bea.content.manager.servlets.jsp.taglib,
    or you can also use the API directly. To use the api, you would do something like
    this:
    Property property = node.getProperty("Attachment");
    ID propertyId = property.getId();
    ID nodeId = node.getId();
    NodeOps nops = repositoryManager.getNodeOps();
    InputStream is = nops.getPropertyBytes(nodeId, propertyId);
    Regards,
    James
    "Manish" <[email protected]> wrote:
    >
    Hi,
    This is regarding bea portal 8.1 content repository
    I have a content node ,type of content is message or article
    Now in this one of the attribute is Attachment..
    I have uploded a XMl file to this attribute
    How do i retrive this file object using bea cutom tags,,
    Are there any custom tag available? or
    can i accessthis document using some kind of API..?
    Can anyone please throw light on this...
    Quick response will be highly appreciated
    Thanx a lot
    Manish Rathi

  • Is it possible to create a file object from a resource?

    Hi all
    Is it possible to create a File from a resource call rather than from a path
    e.g.
    File myFile= new File("C:/j2sdk/sampledir/mypage.htm");is how im doing it now
    how can i call it from a resource something like
    File myFile= new File(this.getClass.getResource("mypage.htm"));

    you may be right
    im trying to load a file into a string then display that string
    my resource thingy isnt working anyway :s
    [code[
    URI pTURI=null;
    URI pBURI=null;
    try
    pTURI= new URI(this.getClass().getResource("/resources/prev_header.htm").toString());
    pBURI= new URI(this.getClass().getResource("/resources/prev_fullpac.htm").toString());
    catch(URISyntaxException e)
    warnUser("URI Error");
    File previewTop = new File(pTURI);
    File previewBtm = new File(pBURI);
    im getting this error
    java.lang.NullPointerException
    at cssCreator.cssCreator.setPreview(cssCreator.java:1263)
    at cssCreator.cssCreator.<init>(cssCreator.java:48)
    at cssCreator.cssCreator.main(cssCreator.java:1681)

  • To find Missing DB Objects from one schema,sid to other schema,sid

    Hi Friends..
    I have an requirement as bellow...
    Recently we migrated from one schema to other ,some of the DB objects are missed while migrating.
    After Migration now the schema and SID are Different for newly created schema
    while comparing the newly created schema2 with old schema1 found that some of the DB objects are missed.
    So i need to find out the difference's from Schema1 to Schema2.
    But now schema 2 is having different sid and schema name and to make the changes in schema2 with respect to schema1.
    Please let me know how to go ahead with this....
    Thanks in advance...

    Hi,
    Here's one way:
    SELECT     object_name
    ,     object_type
    FROM     all_objects
    WHERE     owner     = 'SCHEMA1'     -- Case-sensitive
        MINUS
    SELECT     object_name
    ,     object_type
    FROM     all_objects
    WHERE     owner     = 'SCHEMA2'     -- Case-sensitive
    ;Use a database link for one half of the MINUS, if necessary.
    This will not detect objects that have the same name and type, but are different. For example, if both schemas have a table called TABLE_X, the query above will not display TABLE_X, even if the two tables have different rows and/or columns.

  • Prevent Sender File Adapter from retrying an error file

    Hi,
    I have a situation where there a number of source files[100+] to be picked from a source directory. The files are then processed by an adapter module before they are sent to the IE. Now, in the lot to be picked up there are files which do not conform to the input file structure validations in the module and consequently these would not[and should not] be picked. These files could occur anywhere in the input set and presently the adapter is re-trying the processing of these error files, with the result that the subsequent files are not processed.
    Is there a method to ensure that the entire input file set is processed regardless of the adapter encountering error files in between?
    Thanks,
    Anand

    Yes,
    In your sender communcation channel, you must activate  "Archive faulty source files" flag and indicate a directory for archiving files with errors.
    Regards,
    Carme

  • Preventing missed calls/VMs from registering in the "messages" log

    I'm trying to figure out whether there is a way to get missed calls (and, preferably, notices of voicemail) delivered to a different place on the BB than notices of SMS/email. If I see the little person icon that indicates that there's a voicemail, I don't also need notice of that in the mailbox with the red star on it. Is there a way to make it stop?
    Thanks in advance!

    on your device :
    home screen >> green button >> open menu >> options >> call logs
    there you can choose to log nothing.
    => the phone calls you take, and the ones you miss, appear in the phone log, but no more in the messages list.
    The search box on top-right of this page is your true friend, and the public Knowledge Base too:

Maybe you are looking for

  • Itunes crashing not able to open in Mavericks , even 11.1.3 what to do ?

    Process:         iTunes [868] Path:            /Applications/iTunes.app/Contents/MacOS/iTunes Identifier:      com.apple.iTunes Version:         11.1.3 (11.1.3) Build Info:      iTunes-1113011001003008~1 Code Type:       X86-64 (Native) Parent Proces

  • B noir

    Thankyou so much for your help thus far....I tried your suggestion...but to no avail i.e i changed the drive to P: But Ipod is still not in iTunes. I go to iTunes/Edit/Preferences/iPod and it says no ipod connected...even though windows recognises it

  • Reservation Information

    Dear All, Can anyone tell how to get data from the table or from Std., T.code regarding the reservation created with status open also who has created. Please help me out in htis. Regards, Nagaraj S

  • Create Hyperlink on SharePoint page to Launch Excel Template

    I asked an earlier question which was answered. New question:  I cannot make my SharePoint web page respect this hyperlink (shortened for sake of post) ms-excel:nft|u|https://<site>/subsite/<library>/Forms/MyTemplate.xlsx|s|https://<site>/subsite/<li

  • Delete BLOB image without deleting associated row?

    We have some BLOB data stored out of line. The rows associated with it have been set to NULL, but the image files remain and are filling the tablespace. Is there any way of getting rid of the images without deleting their associated rows? We have als