How to check if the path exists and if not, create it

I'm trying to check if the path given by the user already exists. In case it doesn't, I'd like to create a folder with name given in the same directory.
Let's say path_1: "C:\folder1" and path_2: "C:\folder2", and suppose that folder1 exists but folder2 doesn't. Then if the path given by the user is the path_1, then ok, nothing happens, but if it is the path_2, then the programm should realize that it doesn't exist in C:\ and should ask you whether you want to create it or not.
I know how to do that for files, but not for folders!
Thanks in advance

hi guys,
i`m new at this so im gonne prob. ask a noob`s question...
i have the same issue as in the title.
but when i run :
                                          int a,b,c,d,folderexist=-1;
                                         switch (event)
                                                   case EVENT_COMMIT:
                                                                             GetCtrlVal (panelHandle, PANEL_NAME, name);
                                                                             folderexist = GetFileAttrs (name, &a, &b, &c, &d);
                                                                             if (folderexist==-1)
                                                                                       MakeDir (name);
                                                                                       sprintf...........
                                                                             else.......
if the folder do exists it works perfectly.
if it doesnt - it breaks the run and gives me the message :
                      NON-FATAL RUN-TIME ERROR: "NewScap.c", line 317, col 27, thread id 0x00001B98: Library function error (return value == -1 [0xffffffff]).
(and mark the getfileattrs line in blue)
and when i check the "folderexits" value it shows 2!? not 1 not 0 not even -1, but 2...
can somone please help ?
thanks 
Adi.

Similar Messages

  • How to check if an object exists and how to discard it?

    Greetings,
    I have a main GUI panel in a JFrame that creates a smaller JFrame with a progress bar and text area whenever a process is initiated. I've set the default close operation to DISPOSE_ON_CLOSE as when I set it to EXIT_ON_CLOSE the main GUI panel closes as well (!). But whenever I'm closing the smaller JFrame and initiate a new thread, then the same operation is perform in parallel 2, 3 ,4 times, etc. It seems that the object of the class ProgressGUI which carries all the components of the small panel is not disposed properly. So my question is how can I check if an object exists and if yes how can I discard it? Or in other words how can I discard the JFrame of the small panel without closing the main GUI panel as well?
    thanks,
    Thomas

    I've set the default close operation to DISPOSE_ON_CLOSE thats right.
    So my question is how can I check if an object exists Whenever you create an object, save its refrence somewhere, then just check
    if(reference==null){
             //object does not exist
    }else {
            //object exists
    and if yes how can I discard it? Ensure that no references of the object to be discarded are remaining with any of the objects and then believe in 'Garbage Collector' to do the job! e.g. if there is only one reference to the frame (in your case) somewhere, you can just make an assignment like:
    reference=null;by doing this, you have made the object a candidate for garbage collection. Rest is done by 'Garbage Collector', not you.
    For cases like yours, it is better to make the small frame just once and whenever required just make the frame visible.
    e.g.
    JFrame smallFrame;
    void showSmallFrame(){
        if(smallFrame==null)smallFrame=new SmallFrame(); //or something like that
        smallFrame.setVisible(true);
    }Thanks!

  • 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 to check whether transport path exist between two systems in sld??

    Hi,
         I have two systems namely 'A' and 'B' and created business systems for both of them.Then i created transport path between the two systems.How i check whether what i have done is right in SLD.

    <b>WRT to CMS</b>
    am not sure with this but u can try:
    1. Start CMS: http://<host>:<J2EE Engine http port>/webdynpro/dispatcher/sap.com/tcSLCMS~WebUI/Cms.
    2. Goto lansdscape configurator and check there
    Message was edited by:
            Prabhu  S

  • How to check if the table exists in teh database

    Hi,
    I am using MS Acess and how do i check using the query if the table already exist in the db?
    What is the exact query. Can any one help me.
    Thanks
    Deepti

    This will do it for you and print out the results using JDOM. - %
    package database;
    import org.jdom.Document;
    import org.jdom.Element;
    import org.jdom.output.XMLOutputter;
    import java.sql.Connection;
    import java.sql.DatabaseMetaData;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    public class TableLister
       public static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
       public static final String DATABASE = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\\Documents and Settings\\Michael\\My Documents\\Projects\\Java\\Forum\\data\\DataConnection.mdb";
       public static final String USERNAME = "admin";
       public static final String PASSWORD = "";
       public static void main(String[] args)
          Connection conn = null;
          ResultSet tables = null;
          String driver = "";
          try
             driver = ((args.length > 0) ? args[0] : DRIVER);
             String url = ((args.length > 1) ? args[1] : DATABASE);
             String username = ((args.length > 2) ? args[2] : USERNAME);
             String password = ((args.length > 3) ? args[3] : PASSWORD);
             Class.forName(driver);
             conn = DriverManager.getConnection(url, username, password);
             DatabaseMetaData meta = conn.getMetaData();
             // Bring back ALL tables and views, including SYSTEM tables.
             tables = meta.getTables(null, null, null, null);
             ResultSetMetaData rsmd = tables.getMetaData();
             int numColumns = rsmd.getColumnCount();
             List columnNames = new ArrayList();
             for (int j = 0; j < numColumns; ++j)
                columnNames.add(rsmd.getColumnName(j + 1));
             Element root = new Element("tables");
             int tableCount = 0;
             while (tables.next())
                Element table = new Element("table");
                table.setAttribute("id", Integer.toString(++tableCount));
                for (int j = 0; j < numColumns; ++j)
                   Element column = new Element((String) columnNames.get(j));
                   column.setText(tables.getString((String) columnNames.get(j)));
                   table.addContent(column);
                root.addContent(table);
             conn.close();
             Document doc = new Document(root);
             XMLOutputter outputter = new XMLOutputter("   ", true);
             System.out.println(outputter.outputString(doc));
          catch (ClassNotFoundException e)
             System.err.println("Couldn't load JDBC driver class " + driver);
             e.printStackTrace();
          catch (SQLException e)
             System.err.println("SQL state: " + e.getSQLState());
             System.err.println("SQL error: " + e.getErrorCode());
             e.printStackTrace();
          catch (Exception e)
             e.printStackTrace();
          finally
             close(tables);
             close(conn);
       public static void close(Connection c)
          try
             if (c != null)
                c.close();
          catch (SQLException e)
             e.printStackTrace();
       public static void close(Statement stmt)
          try
             if (stmt != null)
                stmt.close();
          catch (SQLException e)
             e.printStackTrace();
       public static void close(ResultSet result)
          try
             if (result != null)
                result.close();
          catch (SQLException e)
             e.printStackTrace();
    }

  • How can I get the path name and rename it?

    I Hope someone who knows more about automator than I can help me out here. What I'm trying to do is get the path file name, while also changing part of it. Here is my example:
    I can get the path name with this "Get Path" script I found http://automatorworld.com/archives/get-path/all-comments/
    It does half the job so I just need to tweak it but know how. When I get the path this is what I'll get: /Volumes/Public/Creative Services/Campaigns/2010/NCDDiv-32CDV Upgrade/NCDDIV-32Versions.xls
    I need to remove the beginning part"/volumes" to "file://///nhmanmkt01"
    This is so I can send the path from our sever where we keep our files to my windows friends so they can open it.
    Thanks for any help you can provide!

    ok, make the following workflow.
    1. get selected finder items.
    2. run shell script
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    for f in "$@"
    do
    echo "$f"|sed 's%/Volumes%file://///nhmanmkt01%'
    done</pre>
    set the script to accept input as arguments
    3. copy to clipboard
    save it as a finder plugin.

  • How to check if the member exists in essbase cube using IF cond.

    Hello,
    I have a requirement to validate certain accounts and if they exist or not and use them in calc. We have certain list of percent accounts which have some driver amounts. If the user selects the parent account, it should automatically calc with percent accounts to generate the values for all its children.
    The issue is we have lots of accounts and lots of percent accounts, its not that all accounts have the percent accounts. thats the problem.
    When I Fix at a high level of accounts, am getting this error which says that member doesnt exists and return empty member set.
    Error executing formula for [Revcnt] (line 49): attempt to cross a null member in function [@X]
    Its the same even if I use Set Emptymembersets ON;
    The script is below,
    FIX(@Relative({SelectAccount},0),
    "Revcnt"(
    IF(@ISMBR(@MEMBER(@CONCATENATE(@NAME(@CURRMBR("Account")),"%"))
    Condition ;
    ENDIF);
    ENDFIX
    Is there a command to validate if the member exists in the cube or not???
    We are using 11.1.2.1 Essbase on Windows 64bit.

    The silly question first:
    Why not user dynamic calc for the members you need? When updating the structure, you create the formula. Your verification if a member exists will be done in, for example, a select statement that create the dimension.
    Now the complex idea:
    Is it possible in your application recreate the script every time you update the dimension?
    My example:
    Here we have a cube that change the account dimension very often. So the cube have an CalcScript that need to be updated every time the dimension changes.
    For that purpose, we have a process that read the database and recreate the calc with the correct members.
    I never tested that solution with calc manager, but i think it's less complex than recognize the member itself during calculation.

  • How to check if the visitor is registered or Not

    Hi
    im using PHP-Mysql in dreamweaver and i can login
    successfully ..
    now i want to make conditional region based on if the visitor
    is registered or not
    how can i check that?
    thanks in advance.

    It could be done if a user logs in. You could probably set up
    an optional region and set it to display under certain conditions,
    i.e., username=session_variable.

  • How do I change the perspective of an image not created in Illustrator?

    I want to change the perspective of an image I created using another program. I want to add this image to a project I am working on using Illustrator, but the perspective is off.

  • HT3302 my ipod got wet by the sprinklier but i check for the red dot and its not there. Yet i am still having problems with it sense. Does anybody know what is wrong?

    My ipod got a little wet but it wasnt that bad. none of the inside was wet really and the red dot hasnt appeared.........i was wondering if there is something else wrong with it because it keeps pausing when i dont do anything to it

    As a precaution I would dry the iPod by:
    How to fix a wet iPod or iPhone | eHow.comfix-wet-ipod-iphone.html
    After it is dry I would try the standard fixes:
    - Reset. Nothing is lost
    Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Restore from backup
    - Restore to factory defaults/new iPod
    For a nano the drying still applies
    You have to find out how to reset the Nano
    Yu can then try restoring via iTunes

  • How to check whether the Resultset is empty or not ??

    I wanna check whether my Result set is empty or not ( I don't want the no of rows it contains..) i'm using this function...
    boolean result=myResultSet.isAfterLast() | myResultSet.isBeforeFirst() ;
    if (result == true)
    {//Result Set is populated
    else
    {//ResultSet Blank
    Is it ok to do like this ?? Or is there any other functanality to do this, since in big appl..i'm using it more than 10-15 times & it's working fine evrywhere except for one jsp where it is returing TRUE everytime ...
    Help Appreciated !!

    try,
    rs = pstmt.executeQuery();
    boolean b = false;
    if( b = rs.next() ) {
    while( b ) {
    //... rs.getXXX( YYY );
    b = rs.next();
    else {
    //...empty rs processing
    or,
    ResultSet rs = ps.executeQuery();
    if(rs.next()) {
    do {
    System.out.println(rs.getString(1));
    } while(rs.next());
    } else {
    System.out.println('empty result set');
    but I usually avoid using do...while although this may be an exception.

  • How to check if database/table exists in MYSQL

    I am writing a program which accesses databases in MYSQL, is there any way to check if the databases exists on the MYSQL server and if not create one && to check if a table exists and create one of if it does not

    OK, found out that as special permissions needed to create databases I assume it cannot be done via my app but how about Tables

  • DBCA errors and do not create DB

    While I try to create DB using Oracle 9i DBCA, I get error that /etc/oratab file doesn't exist and do not create DB on Unix tru64.
    I already have many DBs on the server, I need to create a small test DB.
    I see the oratab file exist but is renamed with suffix like oratab_h
    now how do I point DBCA to that oratab file. I dont want other db to be disturbed if i run root.sh file.
    any suggestions, shall rename the oratab to original name or run root.sh? what the best solution.
    This looks like Oracle RAC version of DB Software.
    When i open DBCA i get option like:
    What type of database would you like to create or administer?
    1) Oracle cluster database
    2) Oracle Single instance database
    I found no diff in both the options to create DB.
    Appreciate sugestions.
    Thanks

    *** Duplicate Post ***
    KN ... it is not acceptable to repost the same question. If no one answers it is because they don't know the answer or don't wish to answer (we are all volunteers).
    Thank you.

  • How to check for the sub folder in the document library Is already Exist using CSOM?

    Hi,
    My requirement is to create the  folder and sub folder in SharePoint document library. If already exist leave it or create the new folder and the subfolder in the Document library using client side object model
    I able to check for the parent folder.
    But cant able to check the subfolder in the document library.
    How to check for  the sub folder in the document library?
    Here is the code for the folder
    IsFolder alredy Exist.
    private
    string IsFolderExist(string InputFolderName)
    string retStatus = false.ToString();
    try
    ClientContext context =
    new ClientContext(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryLink"]));
                context.Credentials =
    CredentialCache.DefaultCredentials;
    List list = context.Web.Lists.GetByTitle(Convert.ToString(ConfigurationManager.AppSettings["DocumentLibraryName"]));
    FieldCollection fields = list.Fields;
    CamlQuery camlQueryForItem =
    new CamlQuery();
                camlQueryForItem.ViewXml =
    string.Format(@"<View  Scope='RecursiveAll'>
    <Query>
                                            <Where>
    <Eq>
    <FieldRef Name='FileDirRef'/>
    <Value Type='Text'>{0}</Value>
                                                </Eq>
    </Where>
    </Query>
                                </View>",
    @"/sites/test/hcl/"
    + InputFolderName);
                Microsoft.SharePoint.Client.ListItemCollection listItems = list.GetItems(camlQueryForItem);
                context.Load(listItems);
                context.ExecuteQuery();
    if (listItems.Count > 0)
                    retStatus =
    true.ToString();
    else
                    retStatus =
    false.ToString();
    catch (Exception ex)
                retStatus =
    "X02";
    return retStatus;
    thanks
    Sundhar 

    Hi Sundhar,
    According to your description, you might want to check the existence of sub folder in a folder of a library using Client Object Model.
    Please take the code demo below for a try, it will check whether there is sub folder in a given folder:
    public static void createSubFolder(string siteUrl, string libName, string folderServerRelativeUrl)
    ClientContext clientContext = new ClientContext(siteUrl);
    List list = clientContext.Web.Lists.GetByTitle(libName);
    CamlQuery camlQuery = new CamlQuery();
    camlQuery.ViewXml =
    @"<View Scope='RecursiveAll'>
    <Query>
    <Where>
    <Eq>
    <FieldRef Name='FSObjType' />
    <Value Type='Integer'>1</Value>
    </Eq>
    </Where>
    </Query>
    </View>";
    //camlQuery.FolderServerRelativeUrl = "/Lib1/folder1";
    camlQuery.FolderServerRelativeUrl = folderServerRelativeUrl;
    ListItemCollection items = list.GetItems(camlQuery);
    clientContext.Load(items);
    clientContext.ExecuteQuery();
    Console.WriteLine(items.Count);
    if (0 == items.Count)
    //create sub folder here
    Best regards
    Patrick Liang
    TechNet Community Support

  • 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

Maybe you are looking for