15

in SWI Prolog terminal how do I view the current working directory and change the current working directory?

I found:

working_directory(CWD, CWD)

but I dont think its what I need

intrigued_66
  • 16,082
  • 51
  • 118
  • 189

3 Answers3

29

To get the current working directory use working_directory(CWD, CWD).

To change the current working directory use working_directory(_, NewCWD).

Check here to see the manual entry for this predicate.

gusbro
  • 22,357
  • 35
  • 46
  • Tab completion is very handy in case directory names in the path contain space e.g. `working_directory(_, '/home/research/Artificial Intelligence/prolog').` – Imran Ali Aug 18 '18 at 08:32
  • If using `working_directory/2` on Windows and the change will change both the drive and directory as opposed to same drive different directory, then you need to also call `working_directory/2` a second time with just the drive letter to change drives. e.g. You are on `C:\Users\Foo` and need to change to `D:\foo\bar` then you will need to use `working_directory/2` again just with the drive letter. `working_directory(_,"D:/")`. – Guy Coder Jan 11 '20 at 13:14
5

very easy just open prolog on terminal and write working_directory(CWD,'NewPath').

Ex: working_directory(CWD,'/home/user/prologExerc').

manlio
  • 18,345
  • 14
  • 76
  • 126
Zurc
  • 51
  • 1
  • 1
3

To view the current directory use : pwd.

And to change it use : working_directory(CWD,'path_or_location').

Example : working_directory(CWD,'C:/Users/Student/Destop').

Remember to change the direction of slashes in the path name.

Felix Gerber
  • 1,615
  • 3
  • 30
  • 40
Aakash
  • 87
  • 1
  • 2