How do you set PowerShell's default directory?

前端 未结 13 1738
生来不讨喜
生来不讨喜 2021-01-30 01:37

Is there a way to change PowerShell\'s default location?

How do you set PowerShell\'s default working directory?

13条回答
  •  北海茫月
    2021-01-30 01:55

    Instead of unconditionally changing the working directory as mentioned in previous answers, you can write a simple function in the PowerShell profile to use Set-Location to quickly change the working directory whenever necessary.

    Check Jeremy Danyow's answer to create/modify a PowerShell profile.

    Add a function(s) to your PowerShell profile:

    function goto_this {set-location 'your\path\to\some\dir'}
    function goto_that {set-location 'your\path to some\dir with space'}
    

    Just change the function name and directory pointed to. Using quotes on the path is mandatory if it contains spaces. I try to keep the prefix goto_ as it helps in remembering the functions' names.

    You can start typing goto_ then press TAB to cycle through all the added functions (remember to start a new PowerShell window after adding/modifying functions).

提交回复
热议问题