powershell - PowerShell Copy-Item 未创建子文件夹
问题描述
我希望 Copy-Item 复制到目标文件并在途中创建任何子文件夹,但我似乎无法让它工作。
Copy-Item $fullsrc $fulldst -Recurse -Force -Verbose
$fullsrc
并且$fulldst
是带有文件名的完整路径,因为目标文件名与源文件名不同。有没有办法让 Copy-Item 创建子文件夹然后复制文件?
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'.
解决方案
您必须自己创建目标文件的父目录。
# Split-Path with single parameter outputs the parent directory
$null = New-Item (Split-Path $fulldst) -ItemType Directory
Copy-Item $fullsrc $fulldst -Force -Verbose
请注意,-Recurse
当您指定完整的源文件和目标文件路径时,switch 没有用,因此我将其删除。
推荐阅读
- mysql - 如何在没有常规权限的情况下部署 laravel 应用程序
- php - 如何在 WordPress 页面上显示特定帖子?
- linux - 如何检查 Linux 中的 /etc/passwd 文件是否包含无效条目?
- lua - Monaco Editor - 为 Lua 添加 monarch 多行字符串标记
- omnet++ - LEACH CASTALIA 中的 PHY 模型
- javascript - 如何获取 setTimeout 函数的结果?
- java - 尝试在给定字段上为给定类创建比较器时出错
- amazon-s3 - 从集群将整数/字符串写入 pyspark 中的文本文件
- python - 带有 if 语句的 url 的 Python Django request.GET.get 方法
- java - 如何解决 Apache POI“工作簿”可能尚未初始化