Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the current directory of the prompt

Tags:

powershell

I'm writing a script where the first parameter is a filename. But whenever I try to use that string in something that takes a file, I get an error about the file not being found. How do I get the current directory the powershell prompt is in? For some reason it keeps returning my user profile directory:

C:\Users\user1> [System.IO.Directory]::GetCurrentDirectory()
C:\Users\user1

C:\Users\user1> cd\

C:\> cd temp

C:\temp> [System.IO.Directory]::GetCurrentDirectory()
C:\Users\user1
like image 295
Thraka Avatar asked Jul 31 '15 20:07

Thraka


People also ask

How do I find the current directory in command prompt?

Type CD drive: to display the current directory in the specified drive. Type CD without parameters to display the current drive and directory. Use the /D switch to change the current drive in addition to changing the current directory for a drive.

How do I show my current directory?

Use the pwd command to write to standard output the full path name of your current directory (from the /(root) directory). All directories are separated by a slash (/).

How do I find the current working directory in Windows?

For Windows, cd by itself will show you the current working directory. For UNIX and workalike systems, pwd will perform the same task. You can also use the $PWD shell variable under some shells.


1 Answers

pwd is the cmdlet you search for ;)

This is an alias for Get-Location.

like image 192
Martin Brandl Avatar answered Oct 13 '22 01:10

Martin Brandl