Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将文件从层次结构递归复制到单个平面文件夹_Powershell_Copy - Fatal编程技术网

Powershell 将文件从层次结构递归复制到单个平面文件夹

Powershell 将文件从层次结构递归复制到单个平面文件夹,powershell,copy,Powershell,Copy,是否可以将特定文件夹及其子文件夹中包含的所有文件递归地直接复制到一个单一的平面目录,而不再考虑源层次结构文件夹?当然可以。为什么不呢 Counter = 0 Get-ChildItem -Path <Path> -Filter * -Recurse -File | Copy-Item -Destination <Destination Path> -PassThru | Foreach-Object{ $counter++

是否可以将特定文件夹及其子文件夹中包含的所有文件递归地直接复制到一个单一的平面目录,而不再考虑源层次结构文件夹?

当然可以。为什么不呢

Counter = 0
Get-ChildItem -Path <Path> -Filter * -Recurse -File |
    Copy-Item -Destination <Destination Path> -PassThru |
        Foreach-Object{
            $counter++
            Rename-Item -Path $_.FullName -NewName ($_.BaseName + '_' + ("{0:000}" -f $Counter) + $_.Extension)
        }
计数器=0
获取ChildItem-Path-Filter*-Recurse-File|
复制项目-目的地-通过|
Foreach对象{
美元柜台++
重命名项-路径$\.FullName-新名称($\.BaseName++'.+(“{0:000}”-f$计数器)+$\.Extension)
}

我的意思是“包含”和“不包含”,很抱歉出现了这个错误。您可以编辑您的原始帖子来更正它,谢谢您。是否可以将每个复制文件的名称更改为递增计数器(避免重复名称),请?@pindare在PowerShell中大多数事情都是可能的。。。稍微努力一下。