Add quotes around cm_CopyFullNamesToClip
Moderators: white, Hacker, petermad, Stefan2
Add quotes around cm_CopyFullNamesToClip
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"?
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"?
Re: Add quotes around cm_CopyFullNamesToClip
you could make a batch script using sed and nircmdc
and call from TC using
sed can be downloaded at http://gnuwin32.sourceforge.net/packages/sed.htm
nircmdc can be downloaded at https://www.nirsoft.net/utils/nircmd.html
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
Code: Select all
pgm: <path to>\doclipwitquote.cmd
param:%L
nircmdc can be downloaded at https://www.nirsoft.net/utils/nircmd.html
Re: Add quotes around cm_CopyFullNamesToClip
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
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
- 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
Re: Add quotes around cm_CopyFullNamesToClip
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.
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:
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
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 + '"'
Re: Add quotes around cm_CopyFullNamesToClip
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 ?
Re: Add quotes around cm_CopyFullNamesToClip
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!
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 ?
Re: Add quotes around cm_CopyFullNamesToClip
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
Re: Add quotes around cm_CopyFullNamesToClip
Plan D (E?):
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
- 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
Re: Add quotes around cm_CopyFullNamesToClip
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
Re: Add quotes around cm_CopyFullNamesToClip
Thank you!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):
In case someone needs it ...
- COMMAND = cmd.exe
- PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
Works also good in branch view - cm_DirBranch (Menu "Commands" - Branch View (With Subdirs) - Ctrl+B)
Re: Add quotes around cm_CopyFullNamesToClip
Great! Thank you very much!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):
In case someone needs it ...
- COMMAND = cmd.exe
- PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
Thanks also for all the other answers.
Re: Add quotes around cm_CopyFullNamesToClip
Hi,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):
In case someone needs it ...
- COMMAND = cmd.exe
- PARAMETERS = /c CHCP 65001 & (for %%x in (%P%S) DO @echo."%%~x")|clip
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 ?
Re: Add quotes around cm_CopyFullNamesToClip
Look at not null response and adapt to only capture current file:
If you only want quote when necessary, you can use:
For reference, you can give a look here : https://www.alphr.com/echo-without-newline/
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
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/
Re: Add quotes around cm_CopyFullNamesToClip
Thanks.
This must be possible also for multiple files.
Trying it with a Python script.
But how to put entire path of selected files in python list? (%P%S)?
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)
Re: Add quotes around cm_CopyFullNamesToClip
'============================ 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
' 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