在 PowerShell 中创建文件夹别名 [英] Create a folder alias in PowerShell

查看:61
本文介绍了在 PowerShell 中创建文件夹别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以在我的个人资料中创建代表文件夹路径的变量.例如,

I know that I can create variable that represents a folder path in my profile. For example,

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

是否有一种简单的方法可以在 PowerShell 中为目录创建别名?

Is there an easy way to create an alias to a directory in PowerShell?

创建别名

PS> Create-FolderAlias -name $foo -path "C:\Program Files"

基于另一个别名创建别名

Create an alias based on another alias

PS> Create-FolderAlias -name $bar -path $foo + "\Microsoft"

按预期使用别名

PS> cd $foo

如果这些别名能在会话之间保持不变就好了.

It would be nice if these aliases would be persisted between sessions.

推荐答案

您可以使用 新 PSDrive

New-PSDrive foo filesystem 'C:\Program Files'
New-PSDrive bar filesystem 'foo:\Microsoft'
cd foo:

要在会话之间保持不变,您可以将它们添加到您的配置文件脚本 ($profile) 中.

To persist between sessions you could add them to your profile script ($profile).

当然你也可以从一个变量 cd 到一个文件夹

But of course you can also cd to a folder from a variable

$foo = 'C:\Program Files'
$bar = Join-Path $foo 'Microsoft'
cd $foo

这篇关于在 PowerShell 中创建文件夹别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆