Copy filename without extension to clipboard
Moderators: Hacker, petermad, Stefan2, white
Copy filename without extension to clipboard
Can we have a command for copying filename without extension to clipboard??
Re: Copy filename without extension to clipboard
Hello, solid.
Yet, copying the filename without extension can be achieved with the help of Lefteous's lst2clip.
Kind regards,
Karl
No idea whether Christian Ghisler will extend the existing list of copy names to clipboard commands one day.Can we have a command for copying filename without extension to clipboard??
Yet, copying the filename without extension can be achieved with the help of Lefteous's lst2clip.
Kind regards,
Karl
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
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"
Nice onePlace Cursor on the File, Press F7, Press CTRL+C, Press Escape - Done

License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
Or if you've configured TC for Rename-In-Place:
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.
Then whatever your rename-in-place hotkey is, mine is {F2}____ Config | Operation ____ wrote:[X] Select only the file name when renaming (not the extension)
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.
Re: Copy filename without extension to clipboard
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.karlchen wrote:Hello, solid.
Yet, copying the filename without extension can be achieved with the help of Lefteous's lst2clip.
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.
Re: Copy filename without extension to clipboard
Hello, romulous.
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
Oops, true.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.

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
Re: Copy filename without extension to clipboard
Hello Karl.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.
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.
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC
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"
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
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
;;
@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.
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).

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).
I think the second script misses:
before the If statement.
Code: Select all
ClipBoard:=Outlist
- Balderstrom
- Power Member
- Posts: 2148
- Joined: 2005-10-11, 10:10 UTC