SWI Prolog change working directory/get current working directory?
Asked Answered
I

3

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

Intense answered 24/7, 2012 at 14:34 Comment(1)
Why do you not think it's what you need?Clemmer
H
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.

Hermaphroditism answered 12/10, 2012 at 17:45 Comment(2)
Tab completion is very handy in case directory names in the path contain space e.g. working_directory(_, '/home/research/Artificial Intelligence/prolog').Maier
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:/").Infiltration
P
5

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

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

Procurer answered 26/4, 2014 at 11:48 Comment(0)
G
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.

Galoot answered 26/9, 2019 at 9:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.