How to? Copy current directory to clipboard

Feb 23, 2012
240
3
I often need to copy the current directory to the clipboard, for later use in composing TCC commands. I attempted to create an alias for this operation, but I have not yet found the right approach. I tried the following:
echo %_cwds > clip:
However, this has two problems:
1] It includes a CR/LF at the end, so if I paste it on the command line, the command line executes immediately, without giving me a chance to edit it as necessary.
2] Because I have "UnicodeOutput" enabled, the resulting clipboard data includes a BOM at the beginning (FF FE). This prevents TCC from properly pasting the data back into the command line - when I click "paste" on the command line, I get a question mark at the beginning of the path. (Is this WAD? I note that I can successfully paste the same clipboard data into Notepad, or MS Word, or into the unicode editor EditPadPro, and these programs all ignore the BOM and paste only the text; wouldn't it make sense for TCC to also ignore any BOM at the beginning of the clipboard when pasting text?)

In any case, my question remains: how can I copy the value of %_cwds directly to the clipboard, without the leading BOM, and without the CR/LF at the end?
Alternatively, is there any way from within TCC to slightly modify the clipboard after the "echo" command, in order to remove removing the inital two bytes and the final four bytes?
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Try ECHOS - it will not insert the line terminator. You can use the n-th line of the clipboard, without line terminators (whether or not they are in the clipboard) using @clip[n] (0-based!!!). I presume that this would not include a BOM, either - I use ASCII output, so I cannot test. HTH.
 
Feb 23, 2012
240
3
Thanks, Steve! That did the trick regarding the line terminator.
I still have the problem with the initial BOM, however. Rex - is it possible to have TCC ignore a BOM upon paste from the clipboard?
In truth, what I really would like is a way to avoid having that BOM on the clipboard in the first place, because I see now that it does cause problems in some other apps as well. For instance, if I echo the cwd to the clipboard, and then go to Windows-Start-Menu/Run and paste in the path, Explorer cannot process the directory path.
Ideally, I'd suggest, can TCC avoid writing a BOM when redirecting to the CLIP:? I realize this may be too convoluted (because it would require that the redirection operator have special processing depending on the nature of the output device), so instead I think the problem could also be neatly solved with the addition of a TCC option to turn off BOM creation for redirection. That way I can have my alias first turn off BOM creation, then do the redirection, and then reenable BOM creation. What do you think?
(Steve - you are correct that @clip[] takes the text without the BOM. However, as far as I understand, although that helps for batch processing, it won't help me when I want to paste text at will on the clipboard with Ctrl-V.)

Try ECHOS - it will not insert the line terminator. You can use the n-th line of the clipboard, without line terminators (whether or not they are in the clipboard) using @clip[n] (0-based!!!). I presume that this would not include a BOM, either - I use ASCII output, so I cannot test. HTH.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
Pasting from the clipboard should never insert a BOM, because it is not necessarily pasted at the beginning of a file (the only place BOM belongs). AFAIK ctrl-V pastes FROM the clipboard (without changing its content). Placing data in the clipboard using the "cut" (ctrl-X) or "copy" (ctrl-C) edit keys is a different issue.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
After starting TCC with /U (Unicode output) and executing "ECHOS %_CWDS > clip:" I do not get a BOM (?) when I paste to the console using Ctrl-V. I do get the extra character if I paste with a right-click. It's similar inside TCMD ... paste with Ctrl-V, no BOM ... paste with the right-click menu, BOM. I doubt Rex has any control over the console's (QuickEdit's) right-click pasting; don't know about TCMD's right-click menu. Since it was introduced, I have always used Ctrl-V anyway; it's easier.
 
Feb 23, 2012
240
3
Hi Vince,
This is mind-boggling! I'm not using the right click or Ctrl-V; rather I'm using Shift-Ins. I would have thought it a fair assumption that Ctrl-V and Shift-Ins would be mapped to the same routine - yet here we see a drastic difference between their behavior - one pastes with the BOM, and one pastes without!
I don't know which one reflects the default console processing, but it seems that one of the shortcut keys is undergoing some special processing in TCC, while the other is not.

After starting TCC with /U (Unicode output) and executing "ECHOS %_CWDS > clip:" I do not get a BOM (?) when I paste to the console using Ctrl-V. I do get the extra character if I paste with a right-click. It's similar inside TCMD ... paste with Ctrl-V, no BOM ... paste with the right-click menu, BOM. I doubt Rex has any control over the console's (QuickEdit's) right-click pasting; don't know about TCMD's right-click menu. Since it was introduced, I have always used Ctrl-V anyway; it's easier.
 
Feb 23, 2012
240
3
OK, I see now that the problem recurs with any keyboard shortcut that is registered in Customize/Keyboard under Edit/Paste. For instance, I tried setting edit/paste to be ctrl-shift-F8, and indeed, ctrl-shift-f8 produces the question mark.
On the flip side, Ctrl-V is not listed there as a keyboard shortcut; it seems to be an internal keypress, rather than an externally configured keypress. And that makes all the difference here.
In any case, I think this qualifies as a bug - it doesn't make sense for the "paste" action to be different depending on whether the internal shortcut is used or whether a separate shortcut is set. And I believe the correct behavior is that of the Ctrl-V keypress (i.e., no BOM).

Hi Vince,
This is mind-boggling! I'm not using the right click or Ctrl-V; rather I'm using Shift-Ins. I would have thought it a fair assumption that Ctrl-V and Shift-Ins would be mapped to the same routine - yet here we see a drastic difference between their behavior - one pastes with the BOM, and one pastes without!
I don't know which one reflects the default console processing, but it seems that one of the shortcut keys is undergoing some special processing in TCC, while the other is not.
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
Hi Vince,
This is mind-boggling! I'm not using the right click or Ctrl-V; rather I'm using Shift-Ins. I would have thought it a fair assumption that Ctrl-V and Shift-Ins would be mapped to the same routine - yet here we see a drastic difference between their behavior - one pastes with the BOM, and one pastes without!

Shift-Ins is done in TCMD, Ctrl-V is done in TCC.
 
Similar threads
Thread starter Title Forum Replies Date
K copy changing destination current directory Support 1
C Copy (sys) error Support 3
Alpengreis Fixed Crash after copy dialog with big TCC.exception.log Support 5
vefatica Copy/Paste anomaly Support 4
D Documentation Typo in COPY help Support 0
samintz COPY fails to copy from \\wsl$ Support 20
D Differences between TCC and CMD with COPY /b Support 4
fpefpe copy /u and timestamps Support 4
M Strange error messages from TCC in FTP copy Support 7
G TCMD crash when copy Support 3
Alpengreis How to? Copy DIRs with attributes ... Support 4
E Text copy bug Support 1
Alpengreis [TCMD v25.00.24] Problem with copy and paste and the # char via mouse in TCC Support 6
fpefpe copy/cat Support 7
K copy /w slow relative to robocopy /mir Support 0
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
K "copy /z /w" command not deleting read-only files in destination Support 10
D Keystroke to copy previous argument Support 3
A How to? Copy+Paste in TCMD tabs with Ctrl-Shift-Ins? Support 5
RChrismon How to? Copy TCMD.INI to New Version Support 7
R How to? Append files in multiple subfolders using copy? Support 8
Dick Johnson COPY /u (?) Support 9
fpefpe Documentation copy /u Support 7
R How to? copy /q ABC.txt + DEF.txt is appending hex 1A Support 8
D copy /g only shows transfer rate Support 1
J Error "Contents lost before copy" Support 3
B Can copy command concatenate multiple mp3 files Support 2
rps Documentation "Copy+Paste+run" question Support 2
kb6ojs Make /G parameter persistent in COPY/MOVE command? Support 4
fpefpe How to? copy / exclude Support 2
fpefpe robocopy -- copy /w Support 8
C copy /w /p prompts for deletion, but ... Support 3
D Fixed Copy Support 1
fpefpe Documentation copy/move using /c or /u Support 2
samintz WAD Copy/append adds a character Support 3
P Simple RegEx copy Support 9
fromano Fixed COPY ... TO ... crashing Support 3
Alpengreis How to? Copy & Paste without linebreak within TCMD Support 13
D COPY returns ERRORLEVEL 2 Support 5
mdwyer TCC 13 COPY: specified network name is no longer available. Support 5
CWBillow Copy a tree Support 17
J junction copy/move handling Support 6
vefatica Fixed COPY /S ftp://... Support 1
C WAD copy /u ftp local with Timeout? Support 5
D How to? Unregister a copy of Take command Support 1
vefatica FTP copy interrupted Support 2
C How to? COPY ftp folder query Support 7
R How to? TCC 16.03: copy a file to the clipboard? Support 10
jadaml Documentation Is COPY realy doesn't work for any HTTP and FTP? Support 3
T TCC control-C copy operation Support 3

Similar threads