Suppose there is a directory with arbitrary nesting and in these directories at different levels are files.

Task:

Take absolutely all the files that are at different levels and move them to one place.

I would like to see how this is done with a classic batch file (If this is possible) and PowerShell.

  • If no one unsubscribes, I can tell you how it is done on Linux. - don Rumata

1 answer 1

All files are copied from all subdirectories of the SourcePath directory into DestPath (files are dumped into a heap). The names of the files must be unique, otherwise some of them will be lost.

Normal batch file:

 @echo off for /f "delims=*" %%i in ('dir /s /b SourcePath') do copy /y %%~fi DestPath 

Powershell:

 Get-ChildItem SourcePath -Recurse -File | Copy-Item -Dest DestPath 

Well, for Linux:

 find SourcePath -type f -exec cp '{}' DestPath \;