Copy only directory

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
orth0dox
Junior Member
Junior Member
Posts: 3
Joined: 2015-03-23, 21:29 UTC

Copy only directory

Post by *orth0dox »

I found out, that I quite often need to copy directory from one panel to another, but without anything that's inside (no files, or inner folders). I usually do f7 ctrl-c esc tab f7 ctrl-v combo which is tiring and most obviously is very lame way to do what I need. Any suggestions? Thanks!
hi5
Power Member
Power Member
Posts: 642
Joined: 2012-11-03, 11:35 UTC
Contact:

Post by *hi5 »

Just copy the folder (F5) and where it says "only files of this type" enter .. (two dots) that way it will only copy folder(s) but no files.
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
User avatar
Dalai
Power Member
Power Member
Posts: 10036
Joined: 2005-01-28, 22:17 UTC
Location: Meiningen (Südthüringen)

Post by *Dalai »

2hi5
The OP doesn't want to copy subfolders, just the directory itself.

orth0dox
I don't see a way to do this with just with TC. You'll need some kind of script for this. I guess, a simple batch script would do it:

Code: Select all

@echo off
REM %1 = source dir
REM %2 = target dir
set t=%~2%~nx1
echo %~1
echo %~2
echo target: %t%
mkdir "%t%"
You can then create a button with the script like this:

Code: Select all

TOTALCMD#BAR#DATA
c:\copy_dir.cmd
%P%N "%T"
shell32.dll,-153
copy_dir


-1
You can copy the code above and paste it onto TC's button bar to create the button and then adapt it to your needs.

Regards
Dalai
#101164 Personal licence
Ryzen 5 2600, 16 GiB RAM, ASUS Prime X370-A, Win7 x64

Plugins: Services2, Startups, CertificateInfo, SignatureInfo, LineBreakInfo - Download-Mirror
User avatar
HolgerK
Power Member
Power Member
Posts: 5412
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /c for /F  "delims=" %N in
(%F) do md "%T%%N"
%comspec%
create directories in target panel from selected source panel names

1
-1
Without external script file.

Regards
Holger

Edit: just for the case that one of the selected names contains non ASCII characters -> VB-Script solution from an old german thread:
http://ghisler.ch/board/viewtopic.php?p=105917#105917

Anyone with a powershell solution? ;-)
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

PowerShell: Create selected folder in other panel

Post by *Stefan2 »

I hear you :wink:

Or with PowerShell

Hello orth0dox and welcome to the community!


Create folders in other (Target) panel, with names from selected folders in source panel.

Command: PowerShell -NoProfile
Parameter: [face=timesnewroman](Get-Content '%F') | ForEach{ New-Item """%T$_""" -ItemType directory }[/face]
Icon: powershell
Tooltip: Create selected folders in other panel



Shorter, due to PoSh abbreviations:
[face=timesnewroman](GC '%F')|%%{MD """%T$_"""}[/face]




Ready to copy and paste button:

Code: Select all

TOTALCMD#BAR#DATA
PowerShell -NoProfil
(GC '%F')|ForEach{MD \"%T$_\"}
c:\windows\system32\windowspowershell\v1.0\PowerShell.exe
Create selected folders in other panel


-1


Note: for TC I have to escape the quotes. And double the %-sign of the "ForEach" alias "%" .

Note: %F and %T are TC parameter. (Edit a button, press F1, read more about)
%F Long file names without path, stored one name per line in a temp file.
%T inserts the current target path.

Note: Get-Content creates already an array of lines,
which the ForEach-Object process one after the other
to create a new folder in target panel (%T) with name from current line ($_) of temp file list (%F)


Note: search the forum for "usercmd.ini" to be able to store this command in that file, so you can also assign a shortcut to that command.

- - -

More?

(GC '%L')|%%{$FN=$_ -replace ':'; MD \"%T$FN\"}
Create selected folders in other panel with all parents of source folder

(GC '%L')|%%{$FN=$_ -replace '.:'; MD \"%T$FN\"}
Create selected folders in other panel with all parents, but without drive part




 
User avatar
HolgerK
Power Member
Power Member
Posts: 5412
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

Nice :wink:
%UF or %WF and it will work also with unicode names:

Code: Select all

TOTALCMD#BAR#DATA
PowerShell -NoProfil
(GC '%WF')|ForEach{MD \"%T$_\"}
PowerShell.exe
Create selected folders in other panel

1
-1
Regards
Holger
orth0dox
Junior Member
Junior Member
Posts: 3
Joined: 2015-03-23, 21:29 UTC

Post by *orth0dox »

Thanks everyone! Powershell solution works fine, but appearing window annoys me, so I'll stick with vbscript solution suggested by HolgerK.
User avatar
HolgerK
Power Member
Power Member
Posts: 5412
Joined: 2006-01-26, 22:15 UTC
Location: Europe, Aachen

Post by *HolgerK »

orth0dox wrote:..., but appearing window annoys me,..
Just check "[x] Run minimized" inside the button configuration dialog, and the powershell command window will be invisible during execution.

Regards
Holger
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

There is a way to completely hide powershell window:

Code: Select all

powershell.exe -NonInteractive -WindowStyle Hidden ...
BTW it is better to avoid double-quoting %T to prevent path parsing (e.g. if dir name contains '$' powershell will treat '$' and word after it as var name and expand it):

Code: Select all

(GC '%WF') | ForEach { MD ('%T' + $_); }
orth0dox
Junior Member
Junior Member
Posts: 3
Joined: 2015-03-23, 21:29 UTC

Post by *orth0dox »

MVV wrote:There is a way to completely hide powershell window:

Code: Select all

powershell.exe -NonInteractive -WindowStyle Hidden ...
BTW it is better to avoid double-quoting %T to prevent path parsing (e.g. if dir name contains '$' powershell will treat '$' and word after it as var name and expand it):

Code: Select all

(GC '%WF') | ForEach { MD ('%T' + $_); }
Even with -NonInteractive -WindowStyle Hidden flags window appears for a short time, but if it runs minimized it doesn't bother me anymore, thx!
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

MVV wrote:BTW it is better to avoid double-quoting %T to prevent path parsing (e.g. if dir name contains '$' powershell will treat '$' and word after it as var name and expand it):

Code: Select all

(GC '%WF') | ForEach { MD ('%T' + $_); }
No, that will not happen in our case. Me think, because $_ gets just the current
index (line) from the array, and will not expand it afterwards even if it contains a '$'.

But ('%T'+$_) is cool and nice, will keep this to avoid """ and ".



thx
User avatar
MVV
Power Member
Power Member
Posts: 8711
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

I mean that in some dirs "%T$_" will produce wrong results, e.g. "C:\Users\User\AppData\Local\Temp\$mltwcx\$_" will be expanded to "C:\Users\User\AppData\Local\Temp\\dirname": in double-quoted strings sequences like $mltwcx are expanded to values of variables while single-quoted strings are not parsed for variables.

The only problem with '%T' is that path shouldn't contain apostrophe so it isn't universal too...
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Post by *Stefan2 »

Upps, you're right. That is a problem. And apostrophe in path is even a bigger one.

Needs more code, and better a script to load and execute,... to be on the save side.



*moretestsneeded*

 
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Quoting/Escaping arguments in PowerShell can be a real pain.

After plenty of research I found the command line arguments used here.

So instead of:

Code: Select all

-Command "&{&'C:\PathTo\CreateChecksum.ps1' -listFile '%L'}"
you could try

Code: Select all

-Command "&{Your-Code '%L'}"
I replaced all -Path with -LiteralPath (where applicable).
But even then I had to use

Code: Select all

$folderItem.FullName.ToString().Replace('[','`[').Replace(']','`]')
for single square brackets because -LiteralPath is still buggy imho.
Post Reply