Copy Folders Only

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
AnthonyCian
Senior Member
Senior Member
Posts: 265
Joined: 2005-06-16, 01:45 UTC
Location: Thatcher Az. USA

Copy Folders Only

Post by *AnthonyCian »

Hi,
I know the trick how to copy folders only, and not the files in those folders. In the "Only files of this type" field I just put "jiuopeu" something goofy, and all the folders and subfolders are copied over without the files. This method will copy ALL I mean ALL subfolders.
I want to limit the number of Subfolders to the depth of 2. But no matter what I try, I always get the unlimited subfolders copied over. I even used the + which brings up the search feature but I guess I am doing something wrong. Any suggestions would be very helpful.
Thanks,
AC
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: copy folder structure of limited depth

Post by *Stefan2 »

I guess there is a way with TC , AFAIR.




But for the fun I have tested to create a PowerShell script.

[face=timesnewroman]Get-ChildItemtoDepth -Path '%P%N' -ToDepth 3|?{$_.psiscontainer}|%%{New-Item ("""%T"""+ $_.FullName -replace ("""%P""".replace('\', '\\'))) -ItemType directory}[/face]

(Dir %P%N, two sub folder deep, pass directories only.   Create path in target panel by removing %P part first)


EDIT: Found a better syntax, now also works with one or more selected folders:
[face=timesnewroman]TYPE '%L' | %%{ Get-ChildItemtoDepth -Path $_ -ToDepth 2}|?{$_.psiscontainer}|%%{New-Item ('%T'+$_.FullName -replace [regex]::escape('%P')) -ItemType directory}
[/face]


To use create a new button
CMD: PowerShell
Para: <the code from above>
Icon: PowerShell


Select a folder in one panel, open wanted path in target panel, click the button.


- - -

For convenience we utilize a own cmdlet "Get-ChildItemtoDepth"
Add this first to your profile:
- launch powershell
- type: notepad $profile
- add the code below and save
- close the console

Code: Select all

Function Get-ChildItemToDepth {
  Param(
    [String]$Path = $PWD,
    [String]$Filter = "*",
    [Byte]$ToDepth = 255,
    [Byte]$CurrentDepth = 0,
    [Switch]$DebugMode
  )

  $CurrentDepth++
  If ($DebugMode) { $DebugPreference = "Continue" }

  Get-ChildItem $Path | %{
    $_ | ?{ $_.Name -Like $Filter }

    If ($_.PsIsContainer) {
      If ($CurrentDepth -lt $ToDepth -1) {

        # Callback to this function
        Get-ChildItemToDepth -Path $_.FullName -Filter $Filter `
          -ToDepth $ToDepth -CurrentDepth $CurrentDepth

      } Else {

        Write-Debug $("Skipping GCI for Folder: $($_.FullName) " + `
          "(Why: Current depth $CurrentDepth vs limit depth $ToDepth)")

      }
    }
  }
}
#http://www.indented.co.uk/2010/01/22/limit-recursion-depth-with-get-childitem/
 
Last edited by Stefan2 on 2014-09-25, 07:04 UTC, edited 1 time in total.
User avatar
milo1012
Power Member
Power Member
Posts: 1158
Joined: 2012-02-02, 19:23 UTC

Post by *milo1012 »

I think the DirCopy plugin does exactly what you intended.
It might have some problems with Unicode names though.
TC plugins: PCREsearch and RegXtract
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

copy folder structure only

Post by *Stefan2 »

 
Yes, I think DirCopy, or

TreeCopyPlus
CopyTree

is what I had in mind but not had reminded. But i have not tested them myself lately.

So I don't know if they are able to copy folder structure only.


Update:
DirCopy (Announcing Thread) works fine.

 
User avatar
AnthonyCian
Senior Member
Senior Member
Posts: 265
Joined: 2005-06-16, 01:45 UTC
Location: Thatcher Az. USA

Post by *AnthonyCian »

Thanks everyone...
DirCopy is what I needed and works fine.
AC
sorcar
Member
Member
Posts: 100
Joined: 2005-04-12, 17:45 UTC
Location: U.S.

Post by *sorcar »

I know the trick how to copy folders only, and not the files in those folders. In the "Only files of this type" field I just put "jiuopeu" something goofy, and all the folders and subfolders are copied over without the files.
A more elegant way is to put |*.* in the "Only files of this type" field.
Post Reply