在 PowerShell 中创建文件夹别名

编程入门 行业动态 更新时间:2024-10-25 02:29:10
本文介绍了在 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 中创建文件夹别名

本文发布于:2023-11-28 09:40:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:别名   文件夹   PowerShell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!