create alias for path

2019-07-22 03:40发布

Is it possible in PowerShell to create alias for path?

For example: I have to write all time

PS PS C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319

I will happy if I could write

PS PS C:\Users\Jacek>cd dotNet4path

4条回答
【Aperson】
2楼-- · 2019-07-22 03:53

Inspired by @Loïc MICHEL -

`Updated variant for PS 5.1:

set alias to long path using New-PSDrive

Using persist and defining -Root value as network shared path (on local system but appears 'remote') drive F: will persist across PS sessions

change < > entries to your UNC shared path (need to share it first, can select yourself as only authorized user)`

New-PSDrive -Name "F" -Persist -PSProvider "FileSystem" -Root "\\"

查看更多
做个烂人
3楼-- · 2019-07-22 03:55

You could just create a variable in your powershell profile with that path as the value.

Then all you would need to do is something like

cd $dotNet4path

To add something to your profile profile, type $profile, into a powershell window and it will display the path to your powershell profile file. Create it if it does not exist.

Then put this line in the file, save and restart powershell.

$dotNet4path = "C:\windows\microsoft.net\framework\v4.0.30319"
查看更多
Lonely孤独者°
4楼-- · 2019-07-22 04:08

you could use an alias to execute a custom function (you may want to do this in your profile) or use a psdrive :

function path2dotNet{cd "C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319"}  
Set-Alias dot4 -Value path2doc

New-PSDrive dotnet -PSProvider FileSystem -Root "C:\Users\Jacek>cd C:\windows\microsoft.net\framework\v4.0.30319" 
cd dotnet:
查看更多
Summer. ? 凉城
5楼-- · 2019-07-22 04:11

You could use your powershell profile to store the path in a variable:

Add-Content -Value '$dotNet4path = C:\windows\microsoft.net\framework\v4.0.30319' -Path $profile -Force

If you restart your powershell, you can type

cd $dotNet4path
查看更多
登录 后发表回答