问题
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)
回答1:
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 >
来源:https://stackoverflow.com/questions/24456429/how-to-concat-path-and-file-name-for-creation-and-removal