Page 1 of 3

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

Posted: 2023-07-25, 00:17 UTC
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.

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

Posted: 2023-07-25, 07:03 UTC
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

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

Posted: 2023-07-25, 09:59 UTC
by petermad
2Fla$her
funkymonk wrote:Background: I often copy some title from pdf, txt, docx, etc. files and rename the file accordingly

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

Posted: 2023-07-25, 10:41 UTC
by Fla$her
Ah, I read about the title wrong. But this only concerns the button, and not the expanding the functionality.

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

Posted: 2023-07-25, 10:45 UTC
by Hacker
funkymonk,
As I often find myself in a similar situation, I fully support++ this.

Roman

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

Posted: 2023-07-25, 13:28 UTC
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.

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

Posted: 2023-07-26, 02:53 UTC
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.

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

Posted: 2023-07-26, 04:56 UTC
by Galizza
Support++ , but the maximum length of the pasted string should be defined by user.

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

Posted: 2023-07-26, 08:24 UTC
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?

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

Posted: 2023-07-26, 12:05 UTC
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).

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

Posted: 2023-07-26, 14:07 UTC
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.

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

Posted: 2023-07-26, 14:27 UTC
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.

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

Posted: 2023-07-26, 19:48 UTC
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 "_".

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

Posted: 2023-07-27, 08:01 UTC
by ghisler(Author)
I don't handle Ctrl+V in any edit boxes, this is handled by Windows itself.

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

Posted: 2023-07-27, 08:23 UTC
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)