Search code examples
javalinuxdirectorycommandcd

Changing the current directory in Java to implement "cd" command in linux


I'm trying to build a command line interpreter that implements "cd" command in linux. I don't know how the function that suppose to do that shoud work.

I know that this question has already been answered here: Changing the current working directory in Java?

But I'm new to Java and I read alot about this and still don't get how new File(parent, path) would help me change my directory. Any help please?


Solution

  • I used a global variable that holds the path of my current direction. cd would just change it and all other commands use/modify it accordingly. Nothing simpler I guess.