Check if a file exists in network dir (JS)

I've found an old post that has pointed me at:
if (myFile.exists){
alert("File Exists");
else
alert("File doesn't exist");
The problem is that when I use the path  macname/volumes/dir/folder/folder/file.indd (which was created from variables) as myFile the script doesn't find a file that I know exists. All I get is the "File doesn't exist" alert.
Do I need to define myFile as being a string?
I'm still fumbling my way around JS, and converting Applescripts to JS to work cross-platform. Thanks in advance....

To get the path to a file i normally use this little script:
// JavaScript Document
var myFile = File.openDialog("Choose a File");
if((myFile != "")&&(myFile != null)){
    alert("Path: " + myFile + "\nType: " + myFile.type);
Perhaps this c/p can help you:
function mounter() {
    var myDocument = app.activeDocument;
    // we are saving the preview
    var destination = "/Volumes/myfoldername";
    //var destination = "/Users/tn/Documents/Tryksager/Design/";
    var volume = "afp://sub.dn.com/myfoldername";
    try {
        with (myDocument) {
            if(file_name = get_filename(name)) {
                    if (Folder(destination).exists) {
                    //alert("Folder exists: " + Folder(destination));
                    } else {
                    if (confirm ("Mount volume?", false, "Mount volume")) {
                        mount_volume();
                        // volume mounted, do what you need
                    } else {
                        alert("Could not mount");
    } catch ( err ) {
        // No error warning
    function mount_volume() {
        var myScriptFolderPath = pluginPath + "/resources/"; // Path to the applescript
        app.doScript(File(myScriptFolderPath + "mountvolume.scpt"),ScriptLanguage.applescriptLanguage);
//The applescript for mounting volumes
(*set user_name to ""
set Dialog_1 to display dialog "Please enter your user name" default answer ""
set the user_name to the text returned of Dialog_1
set pass_word to ""
set Dialog_2 to display dialog "Please enter your password" default answer "" with hidden answer
set pass_word to the text returned of Dialog_2*)
tell application "Finder"
    try
        mount volume "afp://mysub.mydn.com/myfolder" as user name "myusername" with password "mypassword"
    end try
end tell
Thomas B. Nielsen
http://www.nobrainer.dk

Similar Messages

  • Utl_file.open_file question to check if a file exists and is not empty

    Hello,
    I am trying to write a code where in 3 seperate files are created based on some parameter condition for the extract call.
    Say the parameters are NULL, 'A' and 'B'.
    When Null condition is passed to the extract call then it should create file A and B if records are found. If not it should create empty files.
    It is possible that the parameter to the extract is just 'A' then it would create A with say non zero file and B with zero file.
    Now when the extract is called with 'B' parameter and if the file A already exists and is not empty then I should not touch/overwrite it with empty records.
    Is there any simple way that I can do this to check if a file exists and is non empty?
    I am using
    open_file
    ( gv_utl_file_path
    ,lv_file_name
    ,lv_file_handle
    Please help.
    Thanks

    @OP : No Need to open
    SQL> declare
      2   lb_file_exist boolean;
      3   ln_size number;
      4   ln_block_size number;
      5  begin
      6   sys.utl_file.fgetattr('TEST_DIR','a.txt',lb_file_exist,ln_size,ln_block_size);
      7   if lb_file_exist then
      8    dbms_output.put_line('a Exists');
      9    dbms_output.put_line(to_char(ln_size));
    10   else
    11    dbms_output.put_line('a Not Exists');
    12   end if;
    13   sys.utl_file.fgetattr('TEST_DIR','b.txt',lb_file_exist,ln_size,ln_block_size);
    14   if lb_file_exist then
    15    dbms_output.put_line('b Exists');
    16    dbms_output.put_line(to_char(ln_size));
    17   else
    18    dbms_output.put_line('b Not Exists');
    19   end if;
    20   sys.utl_file.fgetattr('TEST_DIR','c.txt',lb_file_exist,ln_size,ln_block_size);
    21   if lb_file_exist then
    22    dbms_output.put_line('c Exists');
    23    dbms_output.put_line(to_char(ln_size));
    24   else
    25    dbms_output.put_line('c Not Exists');
    26   end if;
    27  end;
    28  /
    a Exists
    0
    b Exists
    3
    c Not Exists
    PL/SQL procedure successfully completed.Edited by: jeneesh on Mar 30, 2012 1:21 AM

  • How can I check if a file exists in CVI Real Time?

    It would also be nice if the help file designated whether functions were supported in real time or now.
    I tried this:
        if(GetFileAttrs (DataFileName,NULL,NULL,NULL,NULL) == -1)
    Michael Chadwell
    Department of Engine and Vehicle R&D
    Southwest Research Institute
    Solved!
    Go to Solution.

    You can check if a file exists in CVI Real-Time using GetFileInfo function.
    The CVI help provides a list of functions available on CVI Real-Time here: CVI Real-Time Functions
    National Instruments
    Product Support Engineer

  • JavaScript: How to check if a file exists.

    Hello Everybody,
    Can you tell me how to check if a file exists using JavaScript and Internet Explorer.
    Browsing on this website I could read about the command "f.exists()" and it was necessary to include "java.io.*".
    Should I use this same command and should I include the same files? Or are there other files and other commands?
    Thanks in advance.

    sorry ya. there is no command to check whether a file exists using javascript. The following code says the object name and value. But it can't say whether the file exists in the harddisk or .. Javascript cannot access database and system resources. If the file exists or not can be checked through the application (ASP, CFML, ..) you are using.

  • How to check whether a file exist in the program folder or not?

    Hi guys,
    how to check whether a file exist in the program folder or not? Let is say i recieve a file name from user then i want to know if the file is there not and act on that base.
    abdul

    Look at the class java.io.File and the .exists() method:
    http://java.sun.com/j2se/1.4/docs/api/java/io/File.html

  • Whats the best way to check weather a file exists online, or not?

    Hi!
    I need to show an Image File in my app which may have different sizes. _1.jpg, _2.jpg and so on.. If, for example, _2.jpg does not exist, I have to take _1.jpg.
    So my question is: is there a better way instead of making/allocating a pic and asking pic != nil ?
    thx!
    alex

    Hi Alex -
    The subject line says "file exists online, or not?". Are you trying to check existence at a network site, or the local file system? I'll cover the local fs first, since that's the easiest. If you need to search a remote site, I think we'll need some more details.
    Assuming an iPhone project (not specified, but your usual topic), NSFileManager will probably be all you need unless the files are localized and/or in the application bundle, in which case you'll want NSBundle. For example, say you're storing all the jpg's in the user's cache directory:
    #define MAXFN 5
    // return nil or the path to the file with the highest numeric suffix
    - (NSString)getPathForBestFile:(NSString)baseName extension:(NSString*)ext {
    NSString *bestFilePath = nil;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    // locate the user's cache directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains(
    NSCachesDirectory, NSUserDomainMask, YES);
    NSString *cacheDirectory = [paths objectAtIndex:0];
    NSLog(@"cacheDirectory=%@", cacheDirectory);
    // loop through file names with numeric suffixes
    for (int i = 1; i <= MAXFN; i++) { />/
    NSString *fileName =
    [NSString stringWithFormat:@"%@_%d.%@", baseName, i, ext];
    NSString *filePath =
    [cacheDirectory stringByAppendingPathComponent: fileName];
    NSLog(@" filePath=%@", filePath);
    if ([fileManager fileExistsAtPath:filePath])
    bestFilePath = filePath;
    return bestFilePath;
    If you need to use NSBundle, see pathForResource:ofType:. If you need to determine the existence of a file at a network site, please give us some details about the kind of server and how much you'll know about the possible file locations.
    Hope that helps!
    - Ray

  • [JS CS3] Check if a file exists

    hello everyone,
    is there a way to check if a file on the local hard drive exists by using javascript?
    thanks a lot,
    jonas

    if (myFile.exists)
    //then do something
    Peter

  • Check if the file exists in the local machine...

    Hi,
    I am getting a problem while checking if the local file exists or not. In the first case the server is same as my local machine. When I try to test if the file exists or not using FILE.exists() it works because I am looking for the file in my machine.
    But when I move the code in Unix the file.exists( ) tries to look in the unix box and not the local machine. My question is how to read it from the local machine?
    We are using jdk v1.2.2 and Iplanet App server v6.0.
    Thanks
    Amol

    What do you mean by "when I move the code in UNIX..."?

  • Result of Executing a Procedure in a Package to check if a file exists

    Hi,
    I have a procedure where i want to check if a name exists in my Oracle Table , for exemple , select name from my_files_processed , if the statement give a result , escape a step and go back to the previous step in the package , if the file doesn't exist in my table go to the next step in my package.
    Any issue on how to do this ??
    Best Regards

    First remove the horrible exception handler(s) which are hiding all errors;
    ie the
    when others
    then
    null;
    end;Then remember the main syntax is
    begin
    packagename.procedurename;
    end;
    /But also remember that procedure name must be declared in the package header if you want to call it. (This is called a public procedure). A private procedure does not have to be declared in the package header and can only be called from within the same package body.
    I always use sqlplus for verification as that is delivered with oracle. You know if it works with sqlplus it will work with any othere client and if it does not, it's usually a client issue.
    from what you have posted, There is nothing obvious as to why it won't work.

  • Text_io checking for the file exists?

    When using TEXT_IO package procedures within a form, How can I check whether the file with the same name exits in the same file path?. I mean what is the text_io procedure? Is there any thing specific?

    something like
    EXCEPTION
    when OTHERS then
       if SQLCODE = -302000 then -- file problems
          MSGBOX('Error: File could not be opened.');
          raise FORM_TRIGGER_FAILURE;
       else
          MSGBOX('Error: ' || SQLERRM);
          raise FORM_TRIGGER_FAILURE;
       end if;

  • How to check whether a file exists or not

    i am in an image uploading utility. i hav succesfully uploaded the image to the server directory (say /uploads). but when displaying the uploaded image, i wanna show the picture only if the image exits (bcoz for some records there is no image). so i hav used this code
    if(new File("uploads/1.jpg").exists())
         out.print("image exists");
    but its not working for me. i got it working fine when i give the full path "D:/Tomcat/webapps/diary/admin/uploads/1.jpg". but i think giving this absolute path is not an efficient method bcoz its a web application, bcoz i may not be able get the absolute path always. so how can i do this by specifieing the relative path
    help me ASAP if u can
    aleens

    Haii ameen
    This is one way to rectify your problem..
    if(new File("uploads/1.jpg").exists())
    out.print("image exists");
    instead of this u can write like
    <%
    ServletConfig cf=getServletConfig();
    ServletContext c=cf.getServletContext();
    if(new File(c.getRealPath("uploads")+"/test.txt").exists())
    out.print("image exists");
    %>If u are not clear of what it is done let me know..i will xplain to you furthur...
    Happy New Year
    Shanu

  • Check if files exist using ABAP

    Hi All,
    I'm currently using FM: FILE_GET_NAME_USING_PATH, and I'd like to do a check to see if the filepath with file (i.e. /com/tmp/file.txt) I am getting back exists or not.
    Very simple question, just not sure what to do.
    Thanks,
    John

    There is a class that provides methods to check, if a file exist or if a certain directory does exist
      CALL METHOD cl_gui_frontend_services=>directory_exist
        EXPORTING
          directory            = lv_path
        RECEIVING
          result               = lv_valid
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          wrong_parameter      = 3
          not_supported_by_gui = 4
          OTHERS               = 5.
          CALL METHOD cl_gui_frontend_services=>file_exist
            EXPORTING
              file                 = x_file_with_path
            RECEIVING
              result               = y_file_exists
            EXCEPTIONS
              cntl_error           = 1
              error_no_gui         = 2
              wrong_parameter      = 3
              not_supported_by_gui = 4
              OTHERS               = 5.
    Hope that helps,
    Michael

  • Check for a file to exist

    Hi all, I have a script which returns the path for a file in this way:
    set outfile to (choose file name with prompt "Choose output file." default name "out.iso")'s POSIX path
    the path is then passed to the shell. Now, I want the script to check whether that file exists and if it does, the script needs to be stopped.
    I tried some ways I found on the web but none seems to work.
    Any help would be appreciated.
    Thank you!
    Lorenzo

    Try using:
    set outfile to (choose file name with prompt "Choose output file." default name "out.iso")'s POSIX path
    set thefile to POSIX file outfile
    tell application "Finder"
    if exists thefile then
    return --or other commands to stop script
    end if
    end tell
    (57077)

  • Checking for a file in a dir + all subdir's

    i'm checking if a file exists in C:/, and all sub directories of C:/. It's easy enough to scan for it in the parent directory, but how would i go about checking all the sub directories also? I couldn't get a system of using the boolean isDirectory working, here's what I have though:
    import java.io.File.*;
    import java.io.*;
    class Readit {
         File file;
         Readit(String fileName) {
              file = new File(fileName);
              check(file);
         void check(File file) {
              try {
                   if(file.exists()) {
                        String files[] = file.list();
                        for(int i = 0; i < files.length; i++) {
                             System.out.println(files);
                             File subdir = new File(files[i]);
                             if(subdir.isDirectory()) {
                                  String infil[] = subdir.list();
                             }{color}
              } catch(NullPointerException nul) {}
         public static void main(String[] args) {
              Readit r = new Readit(args[0]);
    }Edited by: Pattylulz on Jun 10, 2008 8:43 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    It is not clear what exactly you need.
    I assume that you want to find recursively a file/folder with given name:
       private static final FileSystemView fsv =
                FileSystemView.getFileSystemView();
       private static final File checkFile(File pathParent,
                                           String name) {
          final File[] list = pathParent.listFiles();
          if (null == list)
             return null;
          File pathFound = null;
          for (int i = 0; i < list.length && null == pathFound; i++) {
             final File pathCur = list;
    // Can use system display name or name (pathCur.getName())
    final String nameCur = fsv.getSystemDisplayName(pathCur);
    // If you need to search only files, use: pathCur.isFile()
    if (name.equalsIgnoreCase(nameCur)) {// or equals
    pathFound = pathCur;
    } else {
    // All traversable items, but skip links to folders
    boolean isLink = false;
    try {
    isLink = ShellFolder.getShellFolder(pathCur).isLink();
    } catch (FileNotFoundException e) {
    if (fsv.isTraversable(pathCur) && false == isLink) {
    // Recursive is subfolders
    pathFound = checkFile(pathCur, name);
    return pathFound;
    public static void main(String[] args) {
    File file = checkFile(new File("C:\\"), args[0]);
    if (null != file)
    System.out.println("File is found: " + file);
    else
    System.err.println("Cannot find file with name: " + args[0]);
    Mimo                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Applet checking if file exist and if no copy this file

    Halo, everyone,
    I'm new to java and I need an applet which is able to check if certain file exist on user's hard drive and if not to copy it.
    I read that this is possible in certain circumstances, that applet has to be trustes and so on, but that's not my problem. My request is the applet code that checks of existance of certain file.
    I'll lbe very thankful if someone could give me such applet or point me to place where I can see steps to creare it myself.
    Thank you in advace onse again.

    Thnaks a lot for your answers. I really ppreciate!
    How could I make the applet using such permissions i
    how than it would work?I don't understand, in your first post you said "I read that this is possible in certain circumstances, that applet has to be trustes and so on, but that's not my problem. ". I assumed from this that someone else was dealing with the security aspects.
    A starting point to signing Applets is - http://java.sun.com/developer/technicalArticles/Security/Signed/ but Google willl find you a whole load of information.

Maybe you are looking for

  • Return the file name of the field type BLOB

    How can I create the PL/SQL procedure that return the file name of the file insert into the record with a field file_date BLOB. I have this table: TEST with this item: file_name varchar2(20) file_date blob example I have insert with the OraclePortal

  • Internal DVD -R/RW DL is no longer recognized

    My Lacie Lightscribe DVD-R/RW DL is no longer being recognized by my Mac running 10.3.9. Please Help!! Thank You

  • Web Query issues

    Hi All, I have created a web query and assigned it to a role. I have moved the role, web templete and the query from dev to QA was able run the query fine without issues. The problem I am having is when I make changes to the query and transport it to

  • Process Chains - "Natural Number"

    In the Process Chain Planning view there is a column "Natural Number".  For me it is populated with '0' for every row.  I'm curious if anyone knows what this might be in relation to process chains? Thanks, Ken Murray

  • Why can't I activate the microphone on text messages?

    I used the microphone for texting all of the time, and now I am not able to activate the microphone.  I can't seem to turn it back on.  Does anyone know how I can I turn it back on?