I've started to teach myself Haskell, and for that I've installed The Haskell Platform for Windows. I'm using WinGHCi
as of now. I learned that it has command :cd
which is used to change directory. But the question is, how would I know which directory I'm currently in? Without knowing that first why would I want to change directory. I searched a lot but couldn't find the answer.
Please tell me if there is a way to know the current working directory. Preferably I would like to configure the command prompt itself to show the current directory, pretty much like Linux's Console.
Following @Daniel's suggestion, I did these:
.ghci
file (I think it is for Unix-like OS), so I created a file ghci.conf
in C:\Users\Apelles\AppData\Roaming\ghc
folder, as it is instructed here.ghci.conf
.ghci.exe
which is the console-like window. I noticed that it loaded few more modules than it usually used to load before. Here is the snapshot:As you can see it loads more modules, and the last line says,
Can't parse prompt string. Use Haskell syntax.
What does it mean? Which line is causing problem (from the following script)?
let cur fill = do { cwd <- System.Directory.getCurrentDirectory; return (":set prompt \"" ++ cwd ++ fill ++ " \""); } :def doprompt (\_ -> cur ">") :def mycd (\dir -> System.Directory.setCurrentDirectory dir >> cur ">") :doprompt
Also, if I rename ghci.conf
file to some random name, and then start ghci.exe
, it loads these modules:
As I said before, it loads less number of modules, which means with ghci.conf, ghci.exe
does something successfully, but fails at some point. How to fix that?
R is always pointed at a directory on your computer. You can find out which directory by running the getwd (get working directory) function; this function has no arguments. To change your working directory, use setwd and specify the path to the desired folder.
The pwd command can be used to determine the present working directory.
To list the files in the current directory use the dir command, and if you want to change the current directory, use the cd command. You can use the chdir command by itself to print the current directory in MS-DOS and the Windows command line.
If you want to know the current location, in which folder or directory you are while using Windows CMD (Command Line Interface), you can make use of cd command, Command: cd - This command can be used to displays the name of or to change the current directory.
System.Directory.getCurrentDirectory
from the directory
package.
I am not sure if this is the "right" way to do it, but since :!
allows shell commands, you can also get it with the appropriate shell command (of your OS) for reading out the directory or the content (so cd
, ls
and the likes). For example, you can write:
:! cd
It depends what do you need the directory for. If you just want to print it out in your console, then this can help.
All the best!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With