4

Title says it all, how can one change the working directory inside the Torch REPL? I tried using calls to os.execute('cd some_dir') but this doesn't work, as demonstrated here.

th> pwd() --prints: /home/user/Code
th> os.execute('cd ..') --prints: true exit 0
th> pwd() -- prints: /home/user/Code

where pwd() is a a convenience function that calls os.execute('pwd').

sudo-nim
  • 408
  • 3
  • 14
  • 2
    Changing the cwd in a subprocess does not affect the parent's cwd. That is why shells have a built-in `cd` command and there is no `cd` program. – lhf Apr 30 '15 at 00:04

1 Answers1

8

Install the lfs package (probably already installed, if not "luarocks install luafilesystem")

Then,

lfs=require 'lfs'
lfs.chdir(newdir)

Also, in torch REPL, you can execute shell commands with a $ prefix Example:

th> $ls
smhx
  • 2,246
  • 18
  • 22