Using clipboard to paste text as file name: replace newline by space

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

User avatar
funkymonk
Senior Member
Senior Member
Posts: 416
Joined: 2013-12-04, 09:56 UTC

Using clipboard to paste text as file name: replace newline by space

Post by *funkymonk »

When using the content of the clipboard as a file name (especially during in-place rename (Shift+F6) or in dialogs where file names can be entered), TC truncates the content of the clipboard at the first newline char.
I would prefer to replace newlines by a spaces.


Background: I often copy some title from pdf, txt, docx, etc. files and rename the file accordingly -- mostly with in-place rename.
If the title has 2+ lines, I need to copy them line by line or type them manually.
Both is slow and a bit annoying, since the entire title is in the clipboard but cannot be used easily for file names.

Hence my suggestion: Replace newlines by spaces when using text from the clipboard as file name.

Maybe this can be made optional with an INI setting:

Code: Select all

RenameReplaceNewlineBySpace = 0
0 is default (as it is now), 1 is as described above
Of course, it might happen that a user accidentally pastes a "huge" amount of text.
To avoid potential problems with the exit boxes, the max length of the pasted string could still be limited. Maybe by a reasonably chosen constant or by another user-defined INI setting.


Any opinion on that?
Thank you.
Fla$her
Power Member
Power Member
Posts: 2318
Joined: 2020-01-18, 04:03 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Fla$her »

Do you want to expand the basic functionality of Ctrl+V? Somehow I doubt that the author will go for it.
It's easier to use commands to copy names with a space instead of a newline:

Code: Select all

TOTALCMD#BAR#DATA
%ComSpec% /q/c chcp 65001>nul&<nul set
/p=%Q%S|clip
wcmicon2.dll,45
Copy names in one line

1
Overquoting is evil! 👎
User avatar
petermad
Power Member
Power Member
Posts: 14808
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Using clipboard to paste text as file name: replace newline by space

Post by *petermad »

2Fla$her
funkymonk wrote:Background: I often copy some title from pdf, txt, docx, etc. files and rename the file accordingly
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Fla$her
Power Member
Power Member
Posts: 2318
Joined: 2020-01-18, 04:03 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Fla$her »

Ah, I read about the title wrong. But this only concerns the button, and not the expanding the functionality.
Overquoting is evil! 👎
User avatar
Hacker
Moderator
Moderator
Posts: 13067
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Hacker »

funkymonk,
As I often find myself in a similar situation, I fully support++ this.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
funkymonk
Senior Member
Senior Member
Posts: 416
Joined: 2013-12-04, 09:56 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *funkymonk »

Fla$her wrote: 2023-07-25, 07:03 UTC Do you want to expand the basic functionality of Ctrl+V? Somehow I doubt that the author will go for it.
No, I'm sure that there is no need to expand the *basic functionality* of Ctrl+V. Of course, nobody would probably do that.

It's more like an "expansion" of the way in which TC's edit boxes for file names handle input from the clipboard: Simply replace newlines by spaces.
Fla$her
Power Member
Power Member
Posts: 2318
Joined: 2020-01-18, 04:03 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Fla$her »

funkymonk wrote: 2023-07-25, 13:28 UTC It's more like an "expansion" of the way in which TC's edit boxes for file names handle input from the clipboard: Simply replace newlines by spaces.
Understood. As in some browsers, it is implemented for the address bar. I support this option.
Overquoting is evil! 👎
Galizza
Member
Member
Posts: 167
Joined: 2018-09-07, 05:21 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Galizza »

Support++ , but the maximum length of the pasted string should be defined by user.
User avatar
petermad
Power Member
Power Member
Posts: 14808
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Using clipboard to paste text as file name: replace newline by space

Post by *petermad »

but the maximum length of the pasted string should be defined by user.
Doesn't he define it when he mark the text for copying?
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
funkymonk
Senior Member
Senior Member
Posts: 416
Joined: 2013-12-04, 09:56 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *funkymonk »

petermad wrote: 2023-07-26, 08:24 UTC
but the maximum length of the pasted string should be defined by user.
Doesn't he define it when he mark the text for copying?
To avoid confusion:
The maximum length *I was writing about* has nothing to do with the users' wishes. It's a length that limits the pasted text to the amount an edit box can handle without problems. I remember situations (in other applications) where pasting thousands of chars into a UI element caused severe slowdowns or even crashes.

Thus: I guess @ghisler should define a reasonable limit (depending on typical path and file name lengths).
User avatar
Usher
Power Member
Power Member
Posts: 1675
Joined: 2011-03-11, 10:11 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Usher »

Just two remarks to make suggestion much better:

1. There are more characters which should be replaced when pasting as a file/directory name:

Code: Select all

    < (less than)
    > (greater than)
    : (colon)
    " (double quote)
    / (forward slash)
    \ (backslash)
    | (vertical bar or pipe)
    ? (question mark)
    * (asterisk)
Some of them are frequently used in titles (colon, double quotes, question mark), not just EOLs.
TC knows how to manage backslash.

2. Such characters are usually replaced with _UNDERSCORE_ rather than space. It's better solution - anyone can see that there were replacements made.
Andrzej P. Wozniak
Polish subforum moderator
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48088
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Using clipboard to paste text as file name: replace newline by space

Post by *ghisler(Author) »

You can use the multi-rename tool with placeholder
[X]
which does already most of what you suggested:
- replaces line breaks with spaces
- replaces special characters with underscores, except for / and \ which can be used to move files to subfolders.
Author of Total Commander
https://www.ghisler.com
User avatar
funkymonk
Senior Member
Senior Member
Posts: 416
Joined: 2013-12-04, 09:56 UTC

Re: Using clipboard to paste text as file name: replace newline by space

Post by *funkymonk »

I must confess, I wasn't aware of the [X] placeholder in the MRT.
That's certainly useful -- and it can be used with a shortcut launching an MRT profile...

Still, especially for in-place renaming I want to emphasize my initial suggestion and Ushers addition once more:
  1. It would be way faster.
    Especially if just
    • a part of the current filename shall be replaced by the clipboard content OR
    • the clipboard content should just be integrated/added to an existing file name,
    it's quite annoying to set up the MRT accordingly for just a single file.

    Examples:

    "2023-07-27 - TOBEREPLACED" --> "2023-07-27 - some text from the clipboard with line breaks and other chars that are not supported in file names"
    "2023-07-27 - SUFFIX" --> "2023-07-27 - some text from the clipboard with line breaks and other chars that are not supported in file names - SUFFIX"

    In such simple scenarios using the MRT is simply not convenient.

  2. I don't see why TC ignores some of the clipboard content for file names. The information is there -- just use it!
    If a user explicitly pastes some text as file name I guess/assume/hope he does this for good reason.
    Of course some chars are not allowed in file names --> replace by space or "_".
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48088
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Using clipboard to paste text as file name: replace newline by space

Post by *ghisler(Author) »

I don't handle Ctrl+V in any edit boxes, this is handled by Windows itself.
Author of Total Commander
https://www.ghisler.com
User avatar
Stefan2
Power Member
Power Member
Posts: 4159
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Using clipboard to paste text as file name: replace newline by space

Post by *Stefan2 »

There are tools and scripts to modify the clipboard, which can be called by button click or keyboard shortcut.
I myself always use the way via notepad (copy from web or document >> paste in notepad >> adjust the text >> copy and paste where I want to)


 
Post Reply