PowerShell复制项目未创建子文件夹

PowerShell复制项目未创建子文件夹,powershell,copy-item,Powershell,Copy Item,我希望复制项目复制到目标文件,并在途中创建任何子文件夹,但我似乎无法使其工作 Copy-Item $fullsrc $fulldst -Recurse -Force -Verbose $fullsrc和$fulldst是带有文件名的完整路径,因为目标文件名与源文件名不同。有没有办法让“复制项”创建子文件夹,然后复制文件 VERBOSE: Performing the operation "Copy File" on target "Item: D:\mypath\

我希望复制项目复制到目标文件,并在途中创建任何子文件夹,但我似乎无法使其工作

Copy-Item $fullsrc $fulldst -Recurse -Force -Verbose
$fullsrc
$fulldst
是带有文件名的完整路径,因为目标文件名与源文件名不同。有没有办法让“复制项”创建子文件夹,然后复制文件

VERBOSE: Performing the operation "Copy File" on target "Item: D:\mypath\logs\001.123.log
Destination: D:\newpath\newlogs\123.234.log".
Copy-Item : Could not find a part of the path 'D:\newpath\newlogs\123.234.log'.

复制项没有创建文件夹的功能,您需要先创建它

 Copy-Item $fullsrc $(new-item -ItemType Directory -Path $fulldst) -Recurse -Force -Verbose -ErrorAction SilentlyContinue

复制项没有创建文件夹的功能,您需要先创建它

 Copy-Item $fullsrc $(new-item -ItemType Directory -Path $fulldst) -Recurse -Force -Verbose -ErrorAction SilentlyContinue

您必须自己创建目标文件的父目录

# Split-Path with single parameter outputs the parent directory
$null = New-Item (Split-Path $fulldst) -ItemType Directory

Copy-Item $fullsrc $fulldst -Force -Verbose

请注意,
-Recurse
开关在指定完整的源文件和目标文件路径时没有用处,因此我已将其删除。

您必须自己创建目标文件的父目录

# Split-Path with single parameter outputs the parent directory
$null = New-Item (Split-Path $fulldst) -ItemType Directory

Copy-Item $fullsrc $fulldst -Force -Verbose

请注意,
-Recurse
开关在指定完整的源文件和目标文件路径时没有用处,因此我已将其删除。

$fulldst
first中创建目标文件夹在
$fulldst
first中创建目标文件夹我非常确定
-Recurse
没有做任何事情,但我只是想看看它是否有效。我没有见过这样使用
$null=
。这是优于
| Out Null
,还是它们本质上是相同的构造?@YorSubs这是优于
Out Null
,因为它要快得多。请看这里的测量:我非常确定
-Recurse
什么都没做,只是尝试了一下,看看它是否能工作。我没有见过这样使用
$null=
。这是优于
| Out Null
,还是它们本质上是相同的构造?@YorSubs这是优于
Out Null
,因为它要快得多。请参见此处的测量: