0

我的脚本创建了一个文件夹,我在开始时将其定义为变量。

像这样 :

$version = "1.65"

$destpath = "C:\something\someprogramm\$version"

New-Item -ItemType directory -Path "$destPath"

当我现在创建文件夹 1.65 时,我的脚本会用我想复制到那里的所有文件填充这个文件夹。

当我第二次运行脚本时,他将覆盖此文件夹中的内容。

我想防止这种意外覆盖,但是那是怎么做的呢?

4

1 回答 1

1

您可以Test-Path用来检查文件或文件夹是否已经存在。如果退出,则不要创建它。

$destpath = "C:\something\someprogramm\$version"
if(Test-Path $destpath)
{ 
  Write-host "$destpath already exists"
}
else{
New-Item -ItemType directory -Path "$destPath"
}
于 2013-08-30T13:23:00.420 回答