Reputation: 2470
Is it possible to copy all the files contained recursively from a specific folder and its subfolders directly to a only one flat directory without respecting anymore the source hierarchy folders?
Upvotes: 2
Views: 1130
Reputation: 1356
Based on Olaf's answer:
$Counter = 0
Get-ChildItem -Path "./Path" -Filter * -Recurse -File |
Foreach-Object {
$Counter++
Copy-Item -Path $_.FullName -Destination "./Destination/$($_.BaseName + '_' + ("{0:000}" -f $Counter) + $_.Extension)"
}
Upvotes: 0
Reputation: 5232
Of course that's possible. Why not?
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)
}
Upvotes: 2