Set directory path

I have to call native applications from within my java application (using the Runtime.getRuntime().exec() method). That works fine but I need to change the current directory path to a specific path.
How it is done to change the current directory path with java ?
Steffen Kux.

You can use one class of mine that I already posted to this forums some time ago...
/** executes multiple commands in one shell
* @author: Giorgio Maone
import java.io.*;
public class MultiExec {
static final boolean IS_WIN=System.getProperty("os.name").toLowerCase().indexOf("win")==0;
protected String shell=IS_WIN?"":"sh";
public void setShell(String s) {
   shell=s;
public String getShell() {
   return shell;
public Process exec(String cmds[]) throws IOException {
  File f=File.createTempFile("muexec",".bat");
  PrintWriter out=new PrintWriter(new FileWriter(f));
  if(IS_WIN) out.println("@echo off");
  for(int j=0,len=cmds.length; j<len; j++)
    out.println(cmds[j]);
  out.close();
  f.deleteOnExit();
  return Runtime.getRuntime().exec(shell+" "+f.getCanonicalPath());
public int execAndWait(String cmds[]) throws IOException {
   Process p=exec(cmds);
  new Pipe(p.getInputStream(),System.out).connect();
  new Pipe(p.getErrorStream(),System.out).connect();
  new Pipe(System.in,p.getOutputStream()).connect();
  int exitCode=-1;
  try {
   exitCode=p.waitFor();
   } catch(InterruptedException ex) {}
  return exitCode;
static class Pipe {
   private InputStream in;
  private OutputStream out;
  public Pipe(InputStream in, OutputStream out) {
    this.in=in; this.out=out;
  public void connect() {
    new Thread() {
     public void run() {
      try {
       for(int b;(b=in.read())!=-1;) {
         out.write(b);
       out.flush();
     } catch(IOException ex) {}
   }.start();
// Test code
public static void main(String[] args) throws Exception {
String path=args[0];
String drive=path.indexOf(":")==1?path.substring(0,1):"";
System.out.println("\nExit code:"+
  new MultiExec().execAndWait(
   new String[]{
    drive,
    "cd "+path,
    args[1];
}

Similar Messages

  • Dynamic Configuration - Set Directory Path for File Receiver Adapter

    Hi Experts,
    I have a question regarding the dynamic configuration for the file adapter. Is it possible to set a directory path without a message mapping for the file receiver adapter? the problem is that I want to import a pdf document. this pdf document I want to store in a dynamic directory (depending on the filename). so I have to read the filename out of the dynamic configuration and generate (depending on the filename) a directory for this file. Is that possible without a message mapping? I cannot make a message mapping because the file has the pdf format and should not get changed.
    best regards
    Christopher Kühn

    Hi Gaurav,
    I use the ASMA (respectively the filename) for the sender adapter. After the pdf was imported into XI this filename is in the ASMA.
    But what then??? How can I get this filename with the help of the variable substitution? and if I have this filename I have to change this filename a bit to generate the name / path of the directory.
    Please explain it to me detailled
    Thanks and regards
    christopher

  • Can't set directory path in a JTextField

    I've tried to set some directory paths in a JTextField, but nothing displayed in that the JTextField. However, i can print the directory paths one at a time to the console. The following is the code and will explain what I am trying to do:
    fileDialog.showOpenDialog(this);
    File[] classpath = fileDialog.getSelectedFiles();
    if(classpath.length == 0)
    return;
    String cp = "";
    for(int i = 0; i<classpath.length; i++){
    //System.out.println(classpath.getPath());
    cp.concat(classpath[i].getAbsolutePath());
    System.out.println(cp);
    jTextField_cp.setText(cp);
    if I uncomment the first print statement,each path will be shown on a new line in the console. But when I want to print the pathes of the directories in one time( concatenate them first), there's no output at all (the second print statement), I only got some empty new lines in the console. Is it any problems with the use of "cp.concat()" method?

    I'm pretty sure that it'll work if you replace your concat line with this.
    cp = cp.concat(classpath.getAbsolutePath());Java strings are passed by the value of their references, so you are only manipulating the value of the reference, the the string itself, unlike other objects. To work around that, assign cp the new string returned from the concat method.

  • How can I set a new directory path for iPhoto lib & photos?

    I'd like to use an external drive to house all the iPhoto related files including the Library, data files and photos. I don't see an iPhoto Preference to set a different path. Is there another method to accomplish this? Should I edit the directory path as listed in the AlbumData.xml file?
    Thanks!

    Hi Nova,
    copy the ENTIRE iPhoto Library folder (in your Pictures folder) to the external.
    Launch iPhoto with the Option key held down.
    At the prompt choose to open another library
    Navigate to the library on the external and choose it.
    Once it opens on the external this is the library iPhoto will use.
    You can then delete the one on the internal or save it as backup or burn it for backup.

  • Set default directory/path for SaveAs Dialog using WPG_DOCLOAD

    Hi, im trying to set the default directory/path for the SaveAs Dialog called by wpg_docload.download_file.
    I'm not able to find where I can specify the default path.
    Is it something like "htp.p('Content-Disposition: attachment; path=:PX_OUTPUT_DIR" ?
    Thx for your help !
    Here's a part of my code
    owa_util.mime_header( NVL(mime,'application/octet'), FALSE );
    htp.p('Content-length: ' || length);
    htp.p('Content-Disposition: attachment; filename="'||substr(fileName,INSTR(fileName,'/')+1)|| '"');
    owa_util.http_header_close;
    wpg_docload.download_file( lobLoc );
    /*********************/

    I don't believe you're allowed to set the directory path in the Content-Disposition (or any other) header. More accurately, you can set path in the filename, but browsers don't pay any attention to that, they only look at only the terminal filename.
    <p>According to RFC 2183, browsers are supposed to ignore any path information sent with the filename. Even though it's dated 1997, I believe this RFC is still in effect.
    <p>This was done as a security precaution against malicious web apps that might try to download into a system directory or other dangerous place. Also, browsers (usually) allow users to specify their own default download directories. Further, even if you could specify the path, you'd have to do it for any and all filesystems (Linux, Mac HFS, Mac OSX, Windows, etc etc).

  • Terminal Command, how to set defaults write, make application(s) use directory path where file last saved?

    Does anyone know whether there's a terminal command to make all applications remember/use the last directory/path where I last saved a file?
    For example, let's say there are (10) ten PDF's on a website, and I want to use Preview.app to open and save each file to the same directory.
    Problem is, after each time I save a file, Preview.app doesn't automatically remember/use the last directory where I saved my file(s).
    Forcing me to navigate back to the same directory after each time I save a file; super-annoying.
    But, for some reason, when saving images from the web, Firefox remembers the last directory where I saved the file (jpeg).
    So I'm hoping there's some way, possibly a terminal command to set/force all applications (including Preview.app) to remember/use the directory/path where file(s) were last-saved.
    Anyone?

    Get the third-party utility Default Folder X 4.4.9.

  • Creating a DB_ENV environment/setting a directory path for db's in Windows

    I have a small visual studio 2005 c++ program where I am trying to specify which directory to open my database from. I use db_env_create to create my environment and then I try to use DB_ENV->set_data_dir to set my path but it keeps returning a non 0 number and not setting my path. Did I miss any steps?
    Thanks

    Here is an example that I tried and it is crashing at the set_cachesize.
    I don't set the cachesize it then crashes at the dbenv->open. Any idea why I am crashing? I am using Berkeley version 4.6.21 with Windows xp and visual studio 2005.
    Thanks.
    int ret;
    if ((ret = db_env_create(&dbenv, 0)) != 0)
         cout <<"Error Creating Database " << endl;
         return (1);
    if ((ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0)) != 0)
            cout << "Cache size error " << endl;
         dbenv->close(dbenv, 0);
         return (1);
    (void)dbenv->set_data_dir(dbenv, "C:\Documents and Settings");
    if ((ret = dbenv->open(dbenv, "C:\Documents and Settings\champ\My Documents\Visual  
         Studio 2005\Projects",DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | 
         DB_INIT_MPOOL | DB_INIT_TXN,0)) != 0)
           cout << "Cache size error " << endl;
           dbenv->close(dbenv, 0);
           return (1);
    }

  • Setting a directory path

    I'm finding that I can only edit all the files within a directory that the program runs in. Is there a way of setting a directory path and being able to play with the files within.
    I've set the path with the "." before, but could not change anyything, not unless the program resides in the directory.
    I saw setdirectory(), method but couldn't get it to work, is this only for File chooser.
    File directory = new File(".");
    File[] files = directory.listFiles();
    for(int x = 0; x < files.length; x++)
                     if(files[x].isFile()) dim.addElement(files[x].getName());;
            }

    Java doesn't have anything like chdir command. You can use relative paths from the default path or you can use an absolute path in a File object.
    For example:
    new File("c:\\windows\\system32\\cmd.exe").rename("c:\\windows\\system32\\newname.exe");

  • Firefox won't open following update. Can't open Profile Mgr, even when using entire directory path in cmd line

    I'm running Firefox on a Windows 7 machine. Firefox won't open following the latest update. I've read the help articles and it seems like I need to create a new profile because my settings have likely been corrupted. I'm unable to open Profile Mgr, even when using entire directory path in cmd line. I've tried the following commands in the command line:
    firefox -p
    "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -p
    Nothing happens with either command.
    I'm also running Norton Internet Security. I read a help article Re Virtual Browsing features possibly causing a problem. The article said to check the virtualization setting in the internet security software and to clear the virtual cache. I went thru all of the settings menus in Norton Internet Security version 21.6.0.32 and I didn't see anything that looked like 'virtualization" settings, so I assumed that this doesn't apply to me.
    If you have any ideas, I'd sure appreaciate your expertise!!

    ''arcandl [[#question-1038482|said]]''
    <blockquote>
    I'm running Firefox on a Windows 7 machine. Firefox won't open following the latest update. I've read the help articles and it seems like I need to create a new profile because my settings have likely been corrupted. I'm unable to open Profile Mgr, even when using entire directory path in cmd line. I've tried the following commands in the command line:
    firefox -p
    "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -p
    Nothing happens with either command.
    I'm also running Norton Internet Security. I read a help article Re Virtual Browsing features possibly causing a problem. The article said to check the virtualization setting in the internet security software and to clear the virtual cache. I went thru all of the settings menus in Norton Internet Security version 21.6.0.32 and I didn't see anything that looked like 'virtualization" settings, so I assumed that this doesn't apply to me.
    If you have any ideas, I'd sure appreaciate your expertise!!
    </blockquote>
    ''philipp [[#answer-670108|said]]''
    <blockquote>
    hello arcandl, when firefox isn't launching after you double-click on the shortcut this is sometimes also a sign of malware being active on a system.
    you might want to try running a scan with some different other security tools like the [http://www.malwarebytes.org/products/malwarebytes_free free version of malwarebytes] and [http://www.bleepingcomputer.com/download/adwcleaner/ adwcleaner] which are specialised in removing adware and browser hijackers.
    [[Troubleshoot Firefox issues caused by malware]]
    </blockquote>
    Phillip - You're a genius!!! I ran malwarebytes and it resolved my problem. Thank you so much!!!

  • How can I get rid of directory path in front of my folder names in Folder listing in Library mode???

    Im using the most recent version of Lightroom 5.3 (updated through CC - even though this has shown up on previous version) on Windows 7 and all the folders in my library are showing up with the directory path in front of my folder names. How can I get rid of this? I do not see any options in preferences to turn this off. I have also turned off preferences in Windows > Folder Options Control Panel "Display full Path in Title bar" option.
    I have Lightroom on several computers and have set up preferences the same on each workstation, and this only shows up on one workstation.
    Any help would be appreciated.
    You can see from the image  below how this is showing up.
    Thanks
    Thanks!

    Click the little down arrow/+ symbol  next the + - in the folders bar.

  • How can i set a path for my deployment files in weblogic server 10.3

    Hi
    How can i set the path for my WAR ,JAR files while deploying.i am using the wls10.3 version.
    is there any scripts for this ,please provide me.
    my Application is ADF 11g application.

    By "path", I assume you mean "classpath".
    The simplest way is simply to include the jars you need inside the web application or web module's WEB-INF/lib directory, EJB module's META-INF/lib directory, or EAR lib directory.
    If that's not practical, if you use NodeManager to start your servers, you can go to the "Server Start" tab in the server definition in the WebLogic console and edit the "Classpath" field, which defaults to no value. You can specify a classpath value there. Note that if you specify a value there, it REPLACES the default classpath for the server, it doesn't add to it. If you need to just add to it (a much more likely scenario), if the value references the value "$CLASSPATH" in it, that will reference the original classpath value that the server would have had.
    So, for instance, if you wanted to include the MQ jars in the server classpath, you could set a value like this:
    /usr/java/mq/lib/mq.jar:/usr/java/mq/lib/mqstuff.jar:$CLASSPATH

  • How To Find Oracle Home Directory Path...

    Hello,
    I am working on deployment of java web service on Oracle Application Server(LINUX) 10g, EBS - R12.
    I am working on other system and i want to deploy web service remotely on application server.
    And i am not getting the oracle home directory path. I want to find the home directory path remotely.
    so suggest me how to find out path of that.
    or weather i have to install jdevloper on server system and than i have to deploy it,
    or any other alternative way is available.
    Reply as soon as possible......

    Thanks for your reply.
    It's precisely the registry key which got tampered, and there's no ORACLE_HOME environmental variable(Or that too is tampered)
    Now,how to set it to one of the Oracle home directories?
    Regards,
    Bhagat
    !!!!!!!!!!!!!!!!!!!!

  • Finding the directory path in java

    I need to check if a file exists or not before an action is taken. I used File class to get the handle of a file and and then used exist() function to check if it is there. But this function needs to full path to that file. I need to find a directory path at runtime as the application is deployed in different environment and wouldn't know the directory path in each environment. Could somebody help me on this. Thanks,

    fBut this function
    needs to full path to that file. I need to find a
    directory path at runtime as the application is
    deployed in different environment and wouldn't know
    the directory path in each environment. Well, that can only you know where this file is on the different platforms. So maybee you can provide it as a user-input, a parameter to the program or be set in a settings-file which the program reads.
    If you want the full path to the current directory where the java program runs, this works:
    File f=...;
    String absPath=f.getAbsolutePath();
    File absPathFile=new File(absPath);Gil

  • Setting the path in Windows98

    Hello,
    I'd like to run my java application on a computer with Windows 98, and not in the java bin directory. I'm familiar with setting the path variables in Windows XP. You go to control panel -> System -> Advanced -> Environment Variable -> and set them as you like. In Windows 98 there seems to be no such method. Instead I'm hacking away at the autoexec.bat file, but I still can't seem to get it to work. Currently, this is what my autoexec.bat file looks like:
    REM [Header]
    @ECHO OFF
    REM [CD-ROM Drive]
    REM c:\windows\command\mscdex /d:gem001
    REM [Miscellaneous]
    REM [Display]
    REM [Sound, MIDI, or Video Capture Card]
    REM [Mouse]
    c:\windows\cwcdata\cwcdos.exe
    PATH=c:\Program Files\Java\jre1.5.0_01\bin;c:\Program Files\Java\jdk1.5.0_01\bin;
    CLASSPATH=c:\Program Files\Java\jre1.5.0_01\bin;c:\Program Files\Java\jdk1.5.0_01\bin;
    I put the path to both the JRE and JDK in both the PATH and CLASSPATH variables just to be sure. From a DOS prompt, the "java" command seems to work from anywhere, but the "javac" command still only works in the bin directory. Can any think of where I'm going wrong?

    This is copied from the installation Instructions for the product you downloaded. (Note the use of quotation marks - eithr do that or uses the 8.3 format of the directory name)
    Microsoft Windows 98 - To set the PATH permanently, open the AUTOEXEC.BAT file and add or change the PATH statement as follows:
    Start the system editor. Choose "Start", "Run" and enter sysedit, then click OK. The system editor starts up with several windows showing. Go to the window that is displaying AUTOEXEC.BAT
    Look for the PATH statement. (If you don't have one, add one.) If you're not sure where to add the path, add it to the right end of the PATH. For example, in the following PATH statement, we have added the bin directory at the right end:
    PATH C:\WINDOWS;C:\WINDOWS\COMMAND;"C:\PROGRAM FILES\JAVA\JDK1.5.0_<version>\BIN"
    Capitalization doesn't matter. The PATH can be a series of directories separated by semi-colons (;). Microsoft Windows searches for programs in the PATH directories in order, from left to right. You should only have one bin directory for a JDK in the path at a time (those following the first are ignored), so if one is already present, you can update it to jdk1.5.0_<version>.
    To make the path take effect in the current Command Prompt window, execute the following:
    C:> c:\autoexec.bat
    To find out the current value of your PATH, to see if it took effect, at the command prompt, type:
    C:> path

  • Change directory path dynamically using UTL_FILE

    I have a directory TEST_DIR which points to /test/files/
    CREATE OR REPLACE PROCEDURE file_exist (v_country in varchar2) is
    v_check_file_exist BOOLEAN;
    v_dir VARCHAR2 (256) := 'TEST_DIR';
    begin
    UTL_FILE.fgetattr (V_DIR || V_COUNTRY,'file123' ||'.txt', v_check_file_exist, v_a,v_b);
    IF NOT v_check_file_exist THEN
    DBMS_OUTPUT.put_line (TO_CHAR(from_date,'YYYYMMDD')||'.rds');
    END IF;
    END LOOP;
    I would like to change the directory path based on the country which is passed as input to the procedure
    exec file_exist('IND'), so in this case I want the procedure to look for file 'file123.txt' under path /test/files/IND.
    But this is not working..
    But when I change the directory to
    create or replace directory TESTDIR as '/test/files/IND' and then change my UTL_FILE.fgetattr (V_DIR,'file123' ||'.txt', v_check_file_exist, v_a,v_b)(removing || v_country, this time it works.
    am trying this as I have many country folders under the path like
    /test/files/IND
    /test/files/USA
    /test/files/AFR
    and want to change the direcotry path dynamically according to input given.
    Any suggestions

    Make sure that the directories you are trying to write to have been set up for UTL_FILE.
    Refer to UTL_FILE_DIR parameter or CREATE DIRECTORY privilege depending on what DB version you are on.
    HTH
    --Johnnie                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for

  • There was a problem connecting to the server message

    I have started to get the following message when I run Final Cut Pro X There was a problem connecting to the server "soundmedia" The "sound media" server is a PC running windows XP and is switched off. I closed all libraries & set up a new library -

  • HT202879 Pages on Mac and Pages on IPad

    With up grade in pages last fall all my docs in Mac were lost......luckly they were in pages on Ipad where they remain.  Is there anyway to sync them back into Mac?

  • Bulk opening images from an indesign project in photoshop.

    I want to quickly open all the images from an indesign project in photoshop so that I can save them for use on the web. Is there a quicker way to do this than just clicking "edit in" on each individual image? I am using indesign CS4 and photoshop CS5

  • Using a wired shared printer over bluetooth

    With MSI 6967, the user manual says that you can only print directly to bluetooth-enabled printers.  This must be untrue?  Surely it would be relatively easy to construct simple SW that could send print jobs over bluetooth 'Network Access' to the oth

  • PLEASE HELP ME WITH ALE,IDOCS,EDI

    Hey  SAP Experts can you guys help me out with <b>ALE,IDOCS,EDI,SOL </b><b>MAN</b> materials please . mail them to [email protected] Thanks a lot in Advance sd learner