问题描述
我正在尝试以下操作。
$ woohoo = c:\temp\shabang
New-Item -ItemType文件$ woohoo
这将在所需位置创建文件。但是,我想拆分 $ woo
和 $ hoo
并进行类似的操作。
$ woo = c:\temp;
$ hoo = shabang
New-Item -ItemType文件($ woo + $ hoo)
这不起作用,我需要关于如何使其飞行的提示。 cmdlet可以连接 $ woo
和 $ hoo
:
New-Item -ItemType文件(加入路径$ woo $ hoo)
请参见下面的演示:
PS> $ woo = c:\temp
PS> $ hoo = shabang
PS> Join-Path $ woo $ hoo
c:\temp\shabang
PS>
I'm trying the following.
$woohoo = "c:\temp\shabang"
New-Item -ItemType File $woohoo
This creates a file at desired location. However, I'd like to split the $woo
and $hoo
and go something like this.
$woo = "c:\temp"
$hoo = "shabang"
New-Item -ItemType File ($woo + $hoo)
This doesn't work and I need a hint on how to make it fly. This suggestion nor this on worked out when applied to my situation. Apparently - given path format is unsupported.
Suggestions?
Edit
This is what it looks like:
Edit 2
$woo = "c:\temp"; $hoo= "shabang"; New-Item -ItemType File (Join-Path $woo $hoo)
Doing $woo + $hoo
does not return the proper filepath:
PS > $woo = "c:\temp"
PS > $hoo = "shabang"
PS > $woo + $hoo
c:\tempshabang
PS >
Instead, you should use the Join-Path
cmdlet to concatenate $woo
and $hoo
:
New-Item -ItemType File (Join-Path $woo $hoo)
See a demonstration below:
PS > $woo = "c:\temp"
PS > $hoo = "shabang"
PS > Join-Path $woo $hoo
c:\temp\shabang
PS >
这篇关于如何合并用于创建和删除的路径和文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!