Copy filename without extension to clipboard

Here you can propose new features, make suggestions etc.

Moderators: Hacker, petermad, Stefan2, white

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

Post by *Balderstrom »

Code Change above, separate multiple files by a <space> if MULTIPLE_SPACER:=TRUE.
*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 »

Ok, this is becoming weird. With the updated code and highlighting 6 or 7 files and pasting into the 3 text editors I have installed:

-Pasting into EditPad, the blank line is still inserted onto the end (which is what I want to prevent), but each filename is on its own line

-Pasting into Notepad, all filenames are pasted onto the same line, with no spaces in between, but no blank line on the end (e.g. Ahk2ExeAutoHotkeySCCopyCopyREADMEupx - that is 6 filenames all mashed together)

-Pasting into AkelPad, same results as for EditPad

If we could get part of the result from Notepad (the lack of an extra blank line at the end) combined with part of the result from the other 2 editors (one filename per line), I'd be happy.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

I can't reproduce that, although, except for Notepad I don't have those particular Editors installed.

Notepad, Notepad2, Ted's Notepad and EmEditor

In all cases when I select the files:
!_TC_CopyNameOnly.ahk
TCGotoFile.ahk
TC_ST2A.ahk
_Win2K_Mouse.ahk
!__OSV_MPC.ahk

My clipboard output becomes:
!_TC_CopyNameOnly TCGotoFile TC_ST2A _Win2K_Mouse !__OSV_MPC
(No matter which editor I paste it into...)

And changing MULTIPLE_SPACER:=TRUE (instead of FALSE)
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Apparently, when MULTIPLE_SPACER:=FALSE

Most of your editors including Notepad, don't support unix newlines (\n)
Whereas all of my editors, except Notepad DO support unix newlines.

Given that, we'll adjust the script for Windows Newlines.

Code: Select all

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

MULTIPLE_SPACER:=FALSE


STRIP_LAST_CRLF:=!MULTIPLE_SPACER
ClipBoard:=""
outList:=""
PostMessage, 0x433, 2017, 0,, A		; cm_CopyNamesToClip
ClipWait
Loop, Parse, ClipBoard, `n, `r
{
	SplitPath, A_LoopField,,,,fileNameNoEXT
	outList.=( fileNameNoExt ? fileNameNoExt : SubStr(A_LoopField, 1,-1) ) "`r`n"
}
if( STRIP_LAST_CRLF )
	ClipBoard:=SubStr(outList, 1,-2)
else
if( MULTIPLE_SPACER ) {
	StringReplace, outList, outList, `r`n, %A_SPACE%, All
	ClipBoard:=SubStr(outList, 1,-1)
}
else
	ClipBoard:=outList

;; UnComment the next line, Used for example only. (Remove semi-colon)
;MsgBox, ClipBoard: `n////////////`n`n%ClipBoard%`n////////////`n
;;
EDIT: Fix to not exclude directories.
NOTE: if you want the slash after the DirName then replace:
-----> SubStr(A_LoopField, 1,-1) with A_LoopField
Last edited by Balderstrom on 2011-04-04, 23:27 UTC, edited 7 times in total.
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Post by *romulous »

Ok, so with the new code above, pasting into all 3 editors produces the same result:
Ahk2Exe AutoHotkeySC Copy Copy README upx

There are two things with the result that conflict with the way I need the output:

1. There is a space at the end of the last filename. I am assuming the script can't tell when it has copied the last filename and simply does what it does with the other filenames - that is, puts a space after it? Basically, I want to avoid having to make any changes at all to the data pasted. With TC's built in copy, I have to delete the file extension (or '\' if I use it on a folder). With Lst2clip, I have to delete the CRLF. With this one, I have to delete the space.

2. I really need the filenames to be on different lines, as they were before (with no spaces after the name either).
Ahk2Exe
AutoHotkeySC
Copy
Copy
README
upx
Without having a single blank line after 'upx' as Lst2clip does, or this script does. In fact, TC's internal copy actually works in this situation (no extra blank line), but I still can't use it because we can't exclude the file extensions.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

That's easy enough to fix, see adjusted code above.

MULTIPLE_SPACER, should only be true if one doesn't want each item on it's own line, e.g. space separated filenames.

Also the two GLOBAL modifiers are exlusive. If one is set to FALSE, the other should be TRUE. And vica versa. So I just forced that aspect in the code above.
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Post by *romulous »

Thank you :) Yes, that looks about right now. The output in all 3 editors is now:
Ahk2Exe
AutoHotkeySC
Copy
Copy
README
upx

No spaces at the end of any line, no extra blank line at the end, each filename on a separate line. Good job! :)
User avatar
romulous
Senior Member
Senior Member
Posts: 226
Joined: 2003-11-19, 04:10 UTC

Post by *romulous »

Is there any particular reason the code wouldn't copy folder names? I can use the internal TC command for this as there is no extension involved (though it does add a backslash to the end of the folder name that has to be deleted). List2Clip copies folder names though, and it just seems a little strange that the script won't.
User avatar
Balderstrom
Power Member
Power Member
Posts: 2148
Joined: 2005-10-11, 10:10 UTC

Post by *Balderstrom »

Yes, files and folders are two separate things. FileNameNoEXT would be an empty field if the file was a directory.

Code changed 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 »

Ah, yes - that now works with folders too. Thank you again Balderstrom :)
Post Reply