Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

change directory - chdir

  Asked By: Jaxson    Date: Jul 01    Category: Java    Views: 2262
  

i need your help for this simple problem that i
couldn't resolve. ^_^

i've created ftp program using java, but found a
difficulty on "change directory" command.

i tried to implement it using :
Process p = Runtime.getRuntime().exec(cmd);
where cmd is the String = "chdir " + directory_name
but i didn't change to the a particular directory.

here is my function that implements the change
directory:

public void execCd(String param) {
// String param is the directory name that was
passed
// by the calling function
String cmd = "chdir " + param;
Process p = Runtime.getRuntime().exec(cmd);
}

any idea?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Bernard Gutierrez     Answered On: Jul 01

Your method will not work.

What you do in exeCD is to create a new process  to do
CD command. This CD command  will only affect the new
process and will not affect the process you program
runs.

You can solve this problem  through a easy way. When
user type cd XXX, store the new directory  in your
object. When user type ls, then list all the files in
that directory. you need not to change  your program's
running directory physically.

 
Didn't find what you were looking for? Find more on change directory - chdir Or get search suggestion and latest updates.




Tagged: