Copy files to flat file structure

Recently I needed to copy a bunch of files within a lot of subfolders, but I didn’t want the folders.
I just needed a flat file structure. Who needs folders anyway? 🙂

So, my solution is of course powershell.

CLS
$Source = "x:\sourcefolder"
$Destination = "y:\destinationfolder"
$Files = Get-ChildItem -LiteralPath $Source -Recurse -file -Force
[INT]$nr = '1'
ForEach($File in $Files){
    Write-Output "------------------------------------------------------------------------------------------"
    Write-Output "File $nr/$($Files.Count)"
    Write-Output "Copying file: $($File.name)"
    Write-Output "------------------------------------------------------------------------------------------"
    $File | Copy-Item -Destination $Destination
    $nr ++
}

Leave a Reply

Your email address will not be published. Required fields are marked *