【发布时间】:2017-04-13 12:20:28
【问题描述】:
我有一个脚本,可以将具有特定扩展名的文件从源目录移动到目标目录。
我的源目录如下:
文件文件夹
File1.td
-
文件2.td
子文件夹
File3.td
File4.td
我的脚本很短,看起来像:
if(!(Test-Path $SourceDirPath) -or !(Test-Path $DestinationDirPath))
{
Write-Host "The source- or destination path is incorrect, please check "
break
}else
{
Write-Host "Success"
Copy-Item -path $SourceDirPath -Filter "*$extension" -Destination $DestinationDirPath -Recurse
}
我必须提到 $SourceDirPath 来自配置文件,并且只有在我将其声明为 C:\FILESFOLDER\* 时才有效
脚本有效,但不会将文件从子文件夹复制到目标。目的地只有 File1 和 File2。
我的 Copy-Item 命令有什么问题?
【问题讨论】:
-
您想复制子文件夹中的文件和子文件夹本身吗?或者你只想要文件?
-
我想在目的地有完全相同的结构,所以子文件夹和文件
标签: powershell copy-item file-move