[PoweShell] Extract all sources
-
The following three-liner replicates a directory tree under the current directory to a "sources" folder. Then it copies all C# source files into it preserving the original hiearchy. It does not generate folders which would be empty.
$files = ls . -Recurse -include "*.cs" | where { -not (Resolve-Path $_ -Relative).StartsWith(".\sources") }
$files | %{$_.Directory.FullName} | %{(Resolve-Path $_ -Relative).Replace(".\",".\sources\")} | Get-Unique | where{!(Test-Path $_ -type container)} | %{mkdir $_}
$files | %{cp $_ -Destination (Resolve-Path $_ -Relative).Replace(".\",".\sources\")}One can also use a simplier script
Copy-Item -Recurse -Filter *.cs . ..\.\sources
However, this would generate a whole directory tree, including empty directories like "bin" which do not contain any source files.
Greetings - Jacek
-
The following three-liner replicates a directory tree under the current directory to a "sources" folder. Then it copies all C# source files into it preserving the original hiearchy. It does not generate folders which would be empty.
$files = ls . -Recurse -include "*.cs" | where { -not (Resolve-Path $_ -Relative).StartsWith(".\sources") }
$files | %{$_.Directory.FullName} | %{(Resolve-Path $_ -Relative).Replace(".\",".\sources\")} | Get-Unique | where{!(Test-Path $_ -type container)} | %{mkdir $_}
$files | %{cp $_ -Destination (Resolve-Path $_ -Relative).Replace(".\",".\sources\")}One can also use a simplier script
Copy-Item -Recurse -Filter *.cs . ..\.\sources
However, this would generate a whole directory tree, including empty directories like "bin" which do not contain any source files.
Greetings - Jacek