Add quotes around cm_CopyFullNamesToClip

English support forum

Moderators: white, Hacker, petermad, Stefan2

raytc
Senior Member
Senior Member
Posts: 274
Joined: 2004-06-28, 11:03 UTC

Add quotes around cm_CopyFullNamesToClip

Post by *raytc »

Hi,

I would like to know if it is possible to add quotes around "cm_CopyFullNamesToClip"?

I often copy the full path in TC to use it in Conemu or MS Terminal.
Long names with spaces like c:\Program Files\... must be changed to short names c:\Progra~1 or put double quotes around.

Does anyone know how to add double quotes around the path after using "cm_CopyFullNamesToClip"?
User avatar
nsp
Power Member
Power Member
Posts: 1804
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Add quotes around cm_CopyFullNamesToClip

Post by *nsp »

you could make a batch script using sed and nircmdc

Code: Select all

REM do clip with quote : doclipwitquote.cmd
@echo off
<PATH TO>\sed.exe -e 's/.*/\"&\"/' %1 >%1.clip
<PATH TO>\nircmdc.exe clipboard readfile %1.clip
del %1.clip
and call from TC using

Code: Select all

pgm: <path to>\doclipwitquote.cmd
param:%L
sed can be downloaded at http://gnuwin32.sourceforge.net/packages/sed.htm
nircmdc can be downloaded at https://www.nirsoft.net/utils/nircmd.html
User avatar
Stefan2
Power Member
Power Member
Posts: 4157
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Add quotes around cm_CopyFullNamesToClip

Post by *Stefan2 »

For one path to modify I would recommend nircmd too.

- save as myScript.cmd
- create a button to call that script , or a user cmd where you can also assign a keyboard hotkey to

Code: Select all

@ECHO OFF
REM nircmd.exe from NirSoft
SET nirc="%Commander_Path%\TOOLs\NirSoft\nircmdc.exe"
SET tmpfile="C:\TEMP\clipboard_TEMP.txt"
REM
REM cm_CopyFullNamesToClip=2018;Copy names with full path
%nirc% win sendmsg class TTOTAL_CMD 1075, 2018, 0
REM
%nirc% clipboard writefile %tmpfile%
FOR /f "delims=" %%i IN ('FINDSTR . "%tmpfile%"') DO (SET FileContent="%%i")
ECHO %FileContent%>%tmpfile%
%nirc% clipboard readfile  %tmpfile%




For one-or-more-than-one there are other solutions in this forum already (search for cm_CopyFullNamesToClip or Lefteous lst2clip)

For ex.:
CMD: powershell
PARAM: TYPE "%L" | ForEach{$_ -Replace '.*','"""$0""'}|clip



 
raytc
Senior Member
Senior Member
Posts: 274
Joined: 2004-06-28, 11:03 UTC

Re: Add quotes around cm_CopyFullNamesToClip

Post by *raytc »

Thank you.
I've tried them all.

Nsp's script only works once.
Every time I have a new text in my clipboard I get the old one back with this script.

Stefan2's script doesn't work.
The text remains without quotes.

Code: Select all

CMD: powershell
PARAM: TYPE "%L" | ForEach{$_ -Replace '.*','"""$0""'}|clip
works but powershell is terribly slow for me.
It takes 5 to 10 seconds before I have the text with quotes.
Is there a faster alternative? Conemu is faster but the code doesn't work in Conemu.

Sorry I don't know much about sed and powershell.
I wish there would be something like Python in TC:

Code: Select all

'"' + cm_CopyFullNamesToClip + '"'
User avatar
nsp
Power Member
Power Member
Posts: 1804
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Add quotes around cm_CopyFullNamesToClip

Post by *nsp »

raytc wrote: 2022-01-26, 09:56 UTC Thank you.
I've tried them all.

Nsp's script only works once.
Every time I have a new text in my clipboard I get the old one back with this script.
I my case all is working as expected.

How do you call the batch ?
what is the exact content of your batch ?

if in the parameter section you put %L, each time you select new files and call the script again you should have a new name and new content in clipboard.

if you prefer python, you can make it as you want. if you use %L you will get a parameter file name with all the selected file as content.

To debug, you can also add a pause at the end of the batch to see which file is passed as a parameter to sed and nircmdc ?
raytc
Senior Member
Senior Member
Posts: 274
Joined: 2004-06-28, 11:03 UTC

Re: Add quotes around cm_CopyFullNamesToClip

Post by *raytc »

Oh great. I thought it changed the clipboard text, so I had to copy the path first and then use your script.
However, your script does everything at once. Great! Thank you nsp!
nsp wrote: 2022-01-26, 10:45 UTC I my case all is working as expected.

How do you call the batch ?
what is the exact content of your batch ?

if in the parameter section you put %L, each time you select new files and call the script again you should have a new name and new content in clipboard.

if you prefer python, you can make it as you want. if you use %L you will get a parameter file name with all the selected file as content.

To debug, you can also add a pause at the end of the batch to see which file is passed as a parameter to sed and nircmdc ?
User avatar
Stefan2
Power Member
Power Member
Posts: 4157
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Add quotes around cm_CopyFullNamesToClip

Post by *Stefan2 »

raytc wrote: 2022-01-26, 09:56 UTC
Sorry I don't know much about sed and powershell.
I wish there would be something like Python in TC:

Code: Select all

'"' + cm_CopyFullNamesToClip + '"'

You can use every scripting language you want.

Get-Content "%L" | ForEach-Object{ .. .}
"%L" is replaced by the path to a temp file - TC has written the path/name of all selected files to, each file to an own line.

So just use Python to parse that temp file by referring to "%L" and do what you want to each single line content (folders has trailing backslash in that list).




Open an button on TCs buttonbar by right clicking, >> Change...
and in the dialog press F1 for to read the help about the parameters:

%L, %l, %F, %f, %D, %d, %WL, %WF, %UL, %UF
create a list file in the TEMP directory with the names of the selected files and directories





 
NotNull
Senior Member
Senior Member
Posts: 269
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Add quotes around cm_CopyFullNamesToClip

Post by *NotNull »

Plan D (E?):
  • Create a button with
    • COMMAND = cmd.exe
    • PARAMETERS = /c CHCP 65001 & for %%x in (%P%N) DO echo."%%~x"|clip

Now select a file/folder, press the new button and the quoted path is on the clipboard.

Note: doesn't work with multiple selected paths, but as you want to paste in a local terminal, that wouldn't make much sense.

PS: Kudos for being aware that the terminal is responsible for handling in-/output
NotNull
Senior Member
Senior Member
Posts: 269
Joined: 2019-11-25, 20:43 UTC
Location: NL

Re: Add quotes around cm_CopyFullNamesToClip

Post by *NotNull »

Came back to say that someone should suggest to always quote paths (or never) as consistent output is important, when I realized the above can be done with multiple files and folders too (tested):
  • COMMAND = cmd.exe
  • PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
In case someone needs it ...
User avatar
tuska
Power Member
Power Member
Posts: 3758
Joined: 2007-05-21, 12:17 UTC

Re: Add quotes around cm_CopyFullNamesToClip

Post by *tuska »

NotNull wrote: 2022-01-27, 22:21 UTC Came back to say that someone should suggest to always quote paths (or never) as consistent output is important,
when I realized the above can be done with multiple files and folders too (tested):
  • COMMAND = cmd.exe
  • PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
In case someone needs it ...
Thank you! :)

Works also good in branch view - cm_DirBranch (Menu "Commands" - Branch View (With Subdirs) - Ctrl+B)
raytc
Senior Member
Senior Member
Posts: 274
Joined: 2004-06-28, 11:03 UTC

Re: Add quotes around cm_CopyFullNamesToClip

Post by *raytc »

NotNull wrote: 2022-01-27, 22:21 UTC Came back to say that someone should suggest to always quote paths (or never) as consistent output is important, when I realized the above can be done with multiple files and folders too (tested):
  • COMMAND = cmd.exe
  • PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
In case someone needs it ...
Great! Thank you very much!
Thanks also for all the other answers. :)
raytc
Senior Member
Senior Member
Posts: 274
Joined: 2004-06-28, 11:03 UTC

Re: Add quotes around cm_CopyFullNamesToClip

Post by *raytc »

NotNull wrote: 2022-01-27, 22:21 UTC Came back to say that someone should suggest to always quote paths (or never) as consistent output is important, when I realized the above can be done with multiple files and folders too (tested):
  • COMMAND = cmd.exe
  • PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
In case someone needs it ...
Hi,

I noticed that there is a LineFeed at the end if I want to get the path of a single file (most of the time).
The problem with the LineFeed is that if I copy the path into my terminal, it gives an error.

Do you know how to adapt the code so that if there is only one file, then no LineFeed is added ?
User avatar
nsp
Power Member
Power Member
Posts: 1804
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Add quotes around cm_CopyFullNamesToClip

Post by *nsp »

Look at not null response and adapt to only capture current file:

Code: Select all

TOTALCMD#BAR#DATA
cmd
PARAMETERS = /c CHCP 65001 & (for %%x in (%P%N) DO @echo.|set /p=""%%~x"")|clip
wcmicons.dll,11



-1
If you only want quote when necessary, you can use:

Code: Select all

TOTALCMD#BAR#DATA
cmd
PARAMETERS = /c @CHCP 65001 & @echo.|set /p="%P%N"|clip
wcmicons.dll,11



-1

For reference, you can give a look here : https://www.alphr.com/echo-without-newline/
raytc
Senior Member
Senior Member
Posts: 274
Joined: 2004-06-28, 11:03 UTC

Re: Add quotes around cm_CopyFullNamesToClip

Post by *raytc »

Thanks.
This must be possible also for multiple files.

Trying it with a Python script.

Code: Select all

import pyperclip #pyperclip is copy to clipboard plugin
r = ['"' + x + '"' for x in [(%P%S)]]
x = "\n".join(r)
pyperclip.copy(x)
But how to put entire path of selected files in python list? (%P%S)?
User avatar
rus73
Junior Member
Junior Member
Posts: 29
Joined: 2013-05-30, 08:39 UTC
Location: Russia

Re: Add quotes around cm_CopyFullNamesToClip

Post by *rus73 »

'============================ VBS ============================
' Copy the selected names in quotes in the presence of spaces,
' Parameters: %Z%WF (full names) either %Z%WL (full path)
'======================================== Autor: Flasher © ===
If WSH.Arguments.Count Then List = WSH.Arguments(0) Else WSH.Quit
With New RegExp
.Global = 1 : .MultiLine = 1 : .Pattern = "^([^\r\n]*[ \t&][^\r\n]*)$"
All = .Replace(CreateObject("Scripting.FileSystemObject").OpenTextFile(List,,,-1).ReadAll, """$1""")
End With
With CreateObject("SAPI.SpFileStream")
.Format.Type = 1 : .Open List, 3 : .Write All : .Close
End With
With CreateObject("WScript.Shell")
.Run "%ComSpec% /c clip<" & List, 0, 1
End With
Post Reply