Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Powershell: Shortcut for change directory

I just started using Windows Powershell and one major problem I've run into is when I start it, it starts me off in this directory:

C:\Users\Username

However, the directory I usually need to navigate to is in something like:

C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName

And sometimes it goes much deeper. So you can see how it is a little annoying to navigate each time I start the shell to this directory using ten separate cd commands. I was wondering if there was a way to set up a shortcut or alias for something like:

cd C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName

Or possibly I could set some sort of shortcut to the directory only so I could do something like:

cd shortcut

And it would cd to the proper directory. Does anyone have any experience with something like this? Is this a dumb thing to do? I'm very new to using any command line so I'm just trying to get used to navigating around files and folders more easily.

like image 701
Xenostar Avatar asked Aug 12 '14 20:08

Xenostar


People also ask

How do you change directory in PowerShell?

Typing CD\ causes PowerShell to move to the root directory. As you can see, you can use the CD.. or CD\ command to move to a lower level within the folder hierarchy. You can also use the CD command to enter a folder. Just type CD, followed by the folder name.

How do you go to a directory in PowerShell?

Using command-line utilities The Windows PowerShell prompt opens by default at the root of your user folder. Change to the root of C:\ by entering cd c:\ inside the Windows PowerShell prompt.

How do I change directory in PowerShell VS code?

Open any PowerShell file. Press Alt+Shift+S (or whatever keybinding you have for "Powershell: Show Additional Commands from PowerShell Modules"). Select the custom command from the drop-down list of PowerShell commands.

How do I change directory with spaces in PowerShell?

Use " " Double Quotes to Deal With Spaces in the Path While Changing the Current Directory in PowerShell. The cd command changes the current directory in PowerShell. If the path contains spaces, you will get an error when you don't put the path in double quotes " " .


2 Answers

There is also another way to do this:

function PP { cd C:\Users\Username\Dropbox\Websites\2014\Projects\ProjectName }

Set-Alias shortcut `PP`
like image 117
eagle.one Avatar answered Sep 19 '22 12:09

eagle.one


new-psdrive is your friend :

New-PSDrive -Name docs -PSProvider FileSystem -Root "C:\Users\username\Documents"
cd docs:
like image 41
Loïc MICHEL Avatar answered Sep 18 '22 12:09

Loïc MICHEL