Copy filename without extension to clipboard

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

User avatar
solid
Power Member
Power Member
Posts: 747
Joined: 2004-08-09, 11:20 UTC

Copy filename without extension to clipboard

Post by *solid »

Can we have a command for copying filename without extension to clipboard??
User avatar
Sir_SiLvA
Power Member
Power Member
Posts: 3295
Joined: 2003-05-06, 11:46 UTC

Post by *Sir_SiLvA »

As long as we dont have a cmd for that try the following:
Place Cursor on the File, Press F7, Press CTRL+C, Press Escape - Done
Hoecker sie sind raus!
User avatar
karlchen
Power Member
Power Member
Posts: 4603
Joined: 2003-02-06, 22:23 UTC
Location: Germany

Re: Copy filename without extension to clipboard

Post by *karlchen »

Hello, solid.
Can we have a command for copying filename without extension to clipboard??
No idea whether Christian Ghisler will extend the existing list of copy names to clipboard commands one day.

Yet, copying the filename without extension can be achieved with the help of Lefteous's lst2clip.

Kind regards,
Karl
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Example AutoHotKey Script:

Code: Select all

ClipBoard:=""
outList:=""
PostMessage, 0x433, 2017, 0,, A		; cm_CopyNamesToClip
ClipWait
Loop, Parse, ClipBoard, `n
{
	SplitPath, A_LoopField,,,,fileNameNoEXT
	outList.=fileNameNoExt "`n"
}
ClipBoard:=outList

;; UnComment the next line, Used for example only. (Remove semi-colon)
;MsgBox, ClipBoard: `n////////////`n`n%ClipBoard%`n////////////`n
;;
Example Usage:___ wrote:Create a Button or Hotkey within TC,
Command: C:\Program Files\AutoHotkey\AutoHotkey.exe "C:\Users\FOOBAR\Documents\AutoHotkey\TC_CopyFileNamesOnly.ahk"
User avatar
petermad
Power Member
Power Member
Posts: 14808
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

Place Cursor on the File, Press F7, Press CTRL+C, Press Escape - Done
Nice one :-)
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Or if you've configured TC for Rename-In-Place:
____ Config | Operation ____ wrote:[X] Select only the file name when renaming (not the extension)
Then whatever your rename-in-place hotkey is, mine is {F2}
F2 + Ctrl+C

Of course the AHK script will handle all the selected files, instead of just the one where the cursor happens to be.
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Re: Copy filename without extension to clipboard

Post by *romulous »

karlchen wrote:Hello, solid.
Yet, copying the filename without extension can be achieved with the help of Lefteous's lst2clip.
This works, but it is a pity that lst2clip copies the CRLF along with the filename, and the utility has no option to stop that behaviour. It means when you paste the filename into a text document, you get a blank line after the filename and have to delete it manually. I wrote an AutoIt program to strip the CRLF from the lst2clip clipboard data, but it is silly to have to use two programs (one to copy just the filename and one that runs in the background to strip the CRLF character from the end of it), when TC could just as easily do it itself.

I recall asking Christian about the feature a long time ago and I think I was told that no one would use it, so there was no plans to add it (I think I asked if the current copy command could stop adding the '\' character to the end of the copied data and got the same response). Oh well.
User avatar
karlchen
Power Member
Power Member
Posts: 4603
Joined: 2003-02-06, 22:23 UTC
Location: Germany

Re: Copy filename without extension to clipboard

Post by *karlchen »

Hello, romulous.
This works, but it is a pity that lst2clip copies the CRLF along with the filename, and the utility has no option to stop that behaviour.
Oops, true. :oops:
This must have slipped my attention, because as a matter of fact, more often than not I have substituted lst2clip.exe by a pipe construction ( pclip | sed [options] | gclip ) which allows me to perform more conversions than lst2clip.exe can do and which can be used on Linux/Wine as well.

But with respect to the initial request, being able to copy (marked) filename(s) without the extension(s), all this may be overkill. (Unless you use it for other conversions as well.)

Sir_SiLvA's key combination seems the most appropriate solution, because it will work out of the box without having to use any external addons. :)

Kind regards,
Karl
User avatar
solid
Power Member
Power Member
Posts: 747
Joined: 2004-08-09, 11:20 UTC

Post by *solid »

Thanks to everyone for suggestions.
Sir_SiLvA method is the simplest one, but Balderstrom's can be envoked by a single hotkey and works for all selected files.
I'll se to which one I will get used to.
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Re: Copy filename without extension to clipboard

Post by *romulous »

karlchen wrote:Hello, romulous.
But with respect to the initial request, being able to copy (marked) filename(s) without the extension(s), all this may be overkill. (Unless you use it for other conversions as well.)

Sir_SiLvA's key combination seems the most appropriate solution, because it will work out of the box without having to use any external addons. :)
Hello Karl.

If you only want to do one or two copies, I agree. But I do this (filename copies) hundreds of times per day, and having to remove the file extension from the TC internal copy was painful - literally (I didn't even try rename, ctrl+c for the reason that it would be even slower). I will admit - my circumstances are probably a bit odd, and the majority of people would not need the function as much as what I do.

I like the Autohotkey solution posted above, and it has just occurred to me to ask why - when I wrote the Autoit program to remove the CRLF - didn't I just write something to do the copy itself? The answer was "because I didn't think of it" - but now I'm wondering if I could actually do it (I don't have anything against Autohotkey, I just started scripting a while back with Autoit and that is the scripting language I know - not very well I admit, but I do know it a tiny bit).

Anyway, sans an option to copy just the filename in TC, I might go and delve into the Autoit helpfile and see if I can work out a way to do it with Autoit.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Here's an optimized Script if a single file is selected, STRIP the CRLF.
Also, a fix for above, the main loop should likely have an ", `r"

Code: Select all

	#SingleInstance, Force 
;	#Persistent	;; Not for TC Button or TC Hotkey usage.
	#NoEnv
SetBatchLines, -1

STRIP_CRLF:=TRUE
MULTIPLE_SPACER:=FALSE
ClipBoard:=""
outList:=""
PostMessage, 0x433, 2017, 0,, A		; cm_CopyNamesToClip
ClipWait
Loop, Parse, ClipBoard, `n, `r
{
	SplitPath, A_LoopField,,,,fileNameNoEXT
	outList.=fileNameNoExt "`n"
	iLoop:=A_Index
}
if( iLoop == 1 && STRIP_CRLF )
	ClipBoard:=SubStr(outList, 1,-1)
else
{
	if( MULTIPLE_SPACER )
		StringReplace, outList, outList, `n, %A_SPACE%, All
	ClipBoard:=outList
}
;; UnComment the next line, Used for example only. (Remove semi-colon)
;MsgBox, ClipBoard: `n////////////`n`n%ClipBoard%`n////////////`n
;;
Also if one plans to use it very frequently, you should compile it with AHK's included Ahk2Exe.exe, or include it into your main persistent AHK script with an AHK Hotkey, instead of a TC Hotkey.

@romulus
I'd likely be using AutoIT if I had come across that first, as it seems to be more code-like. Although, even though I know C and other languages --- when I look at the same script in AutoIT vs AHK, I find the AHK one easier to discern what it is doing --- even with all of AHK's idiosyncrasies. And Lexikos' version AHK_L has been far improved over the Chris' base code along with being fully Unicode compatible.

EDIT1: Fix: "else ClipBoard:=outList"
As in post below.
EDIT2: Multiple Files, separated by Space --- if option MULTIPLE_SPACER:=TRUE
Last edited by Balderstrom on 2011-04-02, 01:23 UTC, edited 3 times in total.
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Post by *romulous »

Thanks Balderstrom. Rather than try and re-create it in AutoIt, I just downloaded the zip version of Autohotkey, extracted the Compiler folder from the zip file, copied your code to a .ahk file using a text editor, and then compiled it using the Ahk2exe utility in the Compiler folder. Now I have a brand new filename copy button, and don't need to use Lst2clip anymore :)

Edit: Ah, seem to have found a bug. Highlighted two files, hit the copy button, and the script copied the extension for both filenames. That's no good.

Edit: Ok, the multiple selected files is what breaks the AHK script. Select one file at a time, and all is ok. Well, back to Lst2clip (it handles multiple files ok).
User avatar
solid
Power Member
Power Member
Posts: 747
Joined: 2004-08-09, 11:20 UTC

Post by *solid »

I think the second script misses:

Code: Select all

ClipBoard:=Outlist
before the If statement.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Yeah, sorry about that. I must of copy/pasted from the wrong editor window. Script fixed in post above.
*BLINK* TC9 Added WM_COPYDATA and WM_USER queries for scripting.
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Post by *romulous »

Sorry to be a pain - but when you copy multiple filenames, the CRLF is not stripped. Can that be corrected?

(The filename extension being copied when you highlight multiple files is now fixed by the way)
Post Reply