如何合并用于创建和删除的路径和文件名 [英] How to concat path and file name for creation and removal

查看:62
本文介绍了如何合并用于创建和删除的路径和文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下操作。

  $ 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 >

这篇关于如何合并用于创建和删除的路径和文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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