Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Clever Code
  4. [PoweShell] Extract all sources

[PoweShell] Extract all sources

Scheduled Pinned Locked Moved Clever Code
csharpdockerdata-structurestools
2 Posts 1 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lutoslaw
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • L Lutoslaw

      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

      L Offline
      L Offline
      Lutoslaw
      wrote on last edited by
      #2

      Please leave a commentary before giving a 1 vote. X| The script is overcomplicated "a bit", but hey it's wicked isn't it? :-\

      Greetings - Jacek

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups