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
Copy Folders Only
Moderators: Hacker, petermad, Stefan2, white
- AnthonyCian
- Senior Member
- Posts: 265
- Joined: 2005-06-16, 01:45 UTC
- Location: Thatcher Az. USA
PowerShell: copy folder structure of limited depth
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
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.
I think the DirCopy plugin does exactly what you intended.
It might have some problems with Unicode names though.
It might have some problems with Unicode names though.
TC plugins: PCREsearch and RegXtract
copy folder structure only
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.
- AnthonyCian
- Senior Member
- Posts: 265
- Joined: 2005-06-16, 01:45 UTC
- Location: Thatcher Az. USA