Copying filenames in a specific way

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
paw3lk
Junior Member
Junior Member
Posts: 5
Joined: 2010-03-19, 02:25 UTC

Copying filenames in a specific way

Post by *paw3lk »

Hi,

I wonder if there is a way of simplifying what I frequently have to do. I need to copy filenames to the clipboard but I need them in the following format:
filename1.ext; filename2.ext; filename3.ext;
When I use built in Copy selected names to clipboard option it copies them like that:
filename1.ext
filename2.ext
filename3.ext
so what I have to do is paste it to some text editor and replace carriage return character with ;[SPACE] which is very time consuming if done over and over again.

So is there a way of copying filenames to the clipboard the way I need?

Thanks
snake8
Junior Member
Junior Member
Posts: 5
Joined: 2012-05-27, 09:02 UTC

Post by *snake8 »

The simplest way to make fast your repetitive operation is to use the macro method.
A macro is a sequence of operation which you must register and that you can repeat any time you need to.
For do that I use Notepad++, an open source text editor that I have also set as my default totalcmd editor (F4 button),
I suggest to download it from this web address:
notepad-plus-plusDOTorg

I have tried to make a macro for solve your problem, you should copy the following code:

Code: Select all

        <Macro name="ClipBoard" Ctrl="no" Alt="no" Shift="no" Key="0">
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=";" />
            <Action type="0" message="2302" wParam="0" lParam="0" sParam="" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=";" />
            <Action type="0" message="2302" wParam="0" lParam="0" sParam="" />
            <Action type="1" message="2170" wParam="0" lParam="0" sParam=";" />
            <Action type="0" message="2318" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2453" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2326" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2453" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2326" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2310" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2310" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2310" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2310" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2327" wParam="0" lParam="0" sParam="" />
            <Action type="0" message="2451" wParam="0" lParam="0" sParam="" />
        </Macro>
Then, if your Operating system is Windows XP, you have to paste with notepad.exe (or another text
editor which isn't Notepad++) the code in this file:
C:\Documents and Settings\YourUserName\Application Data\Notepad++\shortcuts.xml
Or more generally the path is it:
%userprofile%\Application Data\Notepad++\shortcuts.xml
Please don't perform that copy/paste operation with Notepad++, because it does not allow to change its configuration files if it is open.

Otherwise, if you have got another Operating System, you have to search the folder where shortcuts.xml file is stored.

The code must be placed between delimiters of the macro section:
<Macros> (first delimeter)

<Macro name="Example"........>
....
Various action that macro make
....
</Macro>

</Macros> (second delimeter)
Once this procedure done:

1) Paste the copied file names in Notepad++ text editor.
To make sure the macro works, the cursor must be placed after the last character of final filename (filename3.ext):
filename1.ext
filename2.ext
filename3.ext| <--- cursor
2) Choose the macros menu by clicking on it --> click on "ClipBoard" (or press Enter when it is highlighted).
The output is this:
filename1.ext; filename2.ext; filename3.ext;
Your problem should be solved.

I arbitrarily assigned the macro name (ClipBoard), but you can change it if you want.
Note that you can set a shortcut to invoke the macro.
Last edited by snake8 on 2012-06-03, 12:20 UTC, edited 3 times in total.
paw3lk
Junior Member
Junior Member
Posts: 5
Joined: 2010-03-19, 02:25 UTC

Post by *paw3lk »

Many thanks for taking time to post the solution. It works great as long as there are exactly 3 filenames, what I didn't specify though that the number of filenames I copy can be anything between 2 and 9. Is it possible to modify this macro somehow?

Thanks
User avatar
mhe
Junior Member
Junior Member
Posts: 71
Joined: 2003-02-16, 15:09 UTC

Post by *mhe »

How about a search/replace with "\r\n" as search and "; " as replace (without quotes), with notepad++ and the extended search mode.
Or is it that whole thing that is too much work? Unclear if your doing it all manually or not.
paw3lk
Junior Member
Junior Member
Posts: 5
Joined: 2010-03-19, 02:25 UTC

Post by *paw3lk »

Search/replace is what I currently do but it does take a lot of time if I do the whole thing a lot. That macro does speed things up a bit so that's always some progress but ideally I would prefer not to use any text editor as an intermediate step at all, i.e. copy in desired format straight from the TC but it looks like it's not possible.
User avatar
EricB
Senior Member
Senior Member
Posts: 357
Joined: 2008-03-25, 22:21 UTC
Location: The Netherlands

Post by *EricB »

Hi,

An alternative approach could be the use of Lefteous' tool Lst2Clip (see http://www.totalcmd.net/plugring/list2clip.html). It has extensive ways for copying a file list to the clipboard, and can also replace strings in the process. The way I see it you only need to replace the CRLF sequence by '; '. I'm not sure if this is possible (I'm currently not using the tool myself), but it seems worth the experiment, as the documentation is very clear.

Regards, EricB
User avatar
ZoSTeR
Power Member
Power Member
Posts: 1052
Joined: 2004-07-29, 11:00 UTC

Post by *ZoSTeR »

Save this as "filenames.cmd" or something:

Code: Select all

setlocal enabledelayedexpansion
for /F %%I in (%1) do (
	set concat=!concat! %%I;
)
echo !concat! >filelist.txt
pause
endlocal
and put it on a button with parameter %F
snake8
Junior Member
Junior Member
Posts: 5
Joined: 2012-05-27, 09:02 UTC

Post by *snake8 »

I made a small program in C language, modified from another one (that I've found on net) that reads lines from a file, that should solve your problem.
It reads and modifies the clipboard in your desired form (in a row, separated by ; and tab)... Later you can paste the modified row everywhere you want.
It works in combination with another .exe program that copy/write the clipboard (not made by myself).

You must launch the .bat file (CopyLinesToClipboard.bat) in order to execute the combined programs.

Synthetically, the program works like this:

1)Copy your text lines to the clipboard
2)Launch CopyLinesToClipboard.bat (your clipboard will be overwritten in the way you need it)
3)You can paste the modified clipboards everywhere you want.


You can find the compressed zip file that contains the program (it contains the source code too) here: CopyLinesToCliboard
(I've uploaded the zip file from site droplr file hosting: http://d.pr)
This link lasts one week from today (3 jun).
You can unpack the folder in the zip archive in the path you want (it is a portable a program).


You can do a shortcut of the .bat file (CopyLinesToClipboard.bat) directly into totalcommander for using this program (or in the desktop).
From total commander user guide: - Operation - userinterface - the button bar:
You can easily add buttons to the button bar using Drag&Drop (with pressed SHIFT key).
paw3lk
Junior Member
Junior Member
Posts: 5
Joined: 2010-03-19, 02:25 UTC

Post by *paw3lk »

Thanks again for your replies.
snake8, your solution works almost right, the only thing is that what separates filenames is not ;SPACE but ;TAB. Unless I'm using it incorrectly?

Lst2Clip looked promising but doesn't seem to support replacing carriage return character.
User avatar
mhe
Junior Member
Junior Member
Posts: 71
Joined: 2003-02-16, 15:09 UTC

Post by *mhe »

Autohotkey can do it, tested. The postmessage is equivalent to copynamestoclip, the string replace replaces 'r'n with ";space". But you need autohotkey installed or a compiled exe.

Code: Select all

IfWinActive, ahk_class TTOTAL_CMD
{
  Clipboard := ""
  PostMessage, 1075, 2017
  ClipWait, 1
  StringReplace, clipboard, clipboard, `r`n,;%A_Space%, All
}
snake8
Junior Member
Junior Member
Posts: 5
Joined: 2012-05-27, 09:02 UTC

Post by *snake8 »

paw3lk wrote:Thanks again for your replies.
snake8, your solution works almost right, the only thing is that what separates filenames is not ;SPACE but ;TAB. Unless I'm using it incorrectly?

Lst2Clip looked promising but doesn't seem to support replacing carriage return character.
I admit that I expected that this solution would not be liked (totally) to you, but I liked tab instead of space. ;)
Anyway:

EDIT: I've made some corrections, download new version at this link: program fixed (click)
paw3lk
Junior Member
Junior Member
Posts: 5
Joined: 2010-03-19, 02:25 UTC

Post by *paw3lk »

Perfect, thanks again!
Post Reply