[英]How to use a var in a folder name
I'm creating a powershell
script to create a folder for projects.我正在创建一个
powershell
脚本来为项目创建一个文件夹。
The idea is that I first enter the name of the project, and then use that name in the project folder.这个想法是我首先输入项目的名称,然后在项目文件夹中使用该名称。 Could anyone please give me a hand on how to rename the "00000 - Project Name" in powershell with the variable entered.
任何人都可以帮助我如何在输入变量的情况下重命名 powershell 中的“00000 - 项目名称”。
$PFname = Read-Host -Prompt 'Enter the name of the new project'
Rename-Item -Path "K:\Projects\00000 - Project Name" -NewName "K:\Projects\00000 - Project Name"
Hello you have to do something like this:您好,您必须执行以下操作:
$PFname = Read-Host -Prompt 'Enter the name of the new project'
$path = "K:\Projects\00000 - Project Name"
$newPath = $path -replace "00000 - Project Name$", $PFname
Rename-Item -Path $path -NewName $newPath
The key to complete this is the operator -replace
to whom you have to pass two values, first the value you are looking for and second the value you want to replace.完成此操作的关键是运算符
-replace
您必须向其传递两个值,首先是您要查找的值,其次是您要替换的值。
After that you have both $path
that is your old name and $newPath
which is your result name.之后,您将拥有旧名称 $
$path
和结果名称$newPath
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.