Button for renaming files

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Button for renaming files

Post by *HerbieFlo »

hi!

How can I make a button which renames selected file from:
"FILENAME.WAV"
to
"i1_FILENAME.WAV"

I would like to have ie. 9 buttons. Each button to rename selected file to (i1, i2, i3,... i9)

OR

a better solution would be to make a shortcut on keyboard ie. have a selected file and press CTRL+ALT+1 for "i1",...

Thank you for you time.
Stiltzkin
Member
Member
Posts: 182
Joined: 2004-09-10, 17:15 UTC

Re: Button for renaming files

Post by *Stiltzkin »

copy this and paste it into the buttonbar (rightclick - > Paste)

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /c
rename %P%N "i1_%N"
%comspec%
rename [1]
if you want to set a hotkey for this you need to define a usercmd:
Image: https://upright-waste.000webhostapp.com/images/rename_1.png
Image: https://upright-waste.000webhostapp.com/images/rename_2.png
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Re: Button for renaming files

Post by *HerbieFlo »

i did like you wrote, but "cmd" blinks and does nothing..

i have a version 8.51.

ty
Stiltzkin
Member
Member
Posts: 182
Joined: 2004-09-10, 17:15 UTC

Re: Button for renaming files

Post by *Stiltzkin »

try /k instead of /c.
it will keep the cmd window open. any errors there?
some unicode characters in the filename?
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Re: Button for renaming files

Post by *HerbieFlo »

the syntex of the ocmmand is incorrect
Stiltzkin
Member
Member
Posts: 182
Joined: 2004-09-10, 17:15 UTC

Re: Button for renaming files

Post by *Stiltzkin »

does your button look like this? https://upright-waste.000webhostapp.com/images/rename_3.png

update: totalcmd puts "" around filenames with spaces in it, so you end up with this:

Code: Select all

rename d:\Test File with spaces.txt i1_"Test File with spaces.txt"
that's why it's not working
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Re: Button for renaming files

Post by *HerbieFlo »

yes it does. exactly.

what should i do. even if i try with file without spaces. its the same.

UPDATE!

sorry.. without spaces it works... how can i do workaround to make it work with files with spaces?
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Re: Button for renaming files

Post by *HerbieFlo »

ok... i just added another "" around this (%N):

rename %P%N "i1_"%N""

it does the job
Stiltzkin
Member
Member
Posts: 182
Joined: 2004-09-10, 17:15 UTC

Re: Button for renaming files

Post by *Stiltzkin »

same with powershell (you can select multiple files with this one):

Code: Select all

TOTALCMD#BAR#DATA
Powershell -NoLogo
Get-Content '%UL' | ForEach {$prefix='i1_'} { Rename-Item -LiteralPath $_ -NewName (-join($prefix,(GI -LiteralPath $_).Name)) }
WCMICONS.DLL,32
rename - i1_
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Re: Button for renaming files

Post by *HerbieFlo »

Using this function for a while now. it works perfectly and saves me a lot of time :) thank you all!

In addition, it happens sometimes that i have to rename it. which means I have to delete first three letters.

Is it possible to scrypt that it deletes the first three letters of a selected file?

Thank you.
Stiltzkin
Member
Member
Posts: 182
Joined: 2004-09-10, 17:15 UTC

Re: Button for renaming files

Post by *Stiltzkin »

Code: Select all

TOTALCMD#BAR#DATA
Powershell -NoLogo
gc '%UL' | %% {ren -LiteralPath $_ -NewName (((GI -LiteralPath $_).Name).substring(3))}
WCMICONS.DLL,32
remove first 3

Code: Select all

Get-Content '%UL' | ForEach {Rename-Item -LiteralPath $_ -NewName (((GI -LiteralPath $_).Name).substring(3))}
User avatar
petermad
Power Member
Power Member
Posts: 14741
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Button for renaming files

Post by *petermad »

This button should also do it - it requires TC 10.00

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
rename %P%N "i1_"%N:~3,255""
wcmicons.dll,63
Rename and cut off 3 first charaters

1
-1
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.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
HerbieFlo
Junior Member
Junior Member
Posts: 9
Joined: 2021-05-21, 03:45 UTC

Re: Button for renaming files

Post by *HerbieFlo »

PERFECT! I love 10!

FYI... not for this topic.
I don't know why, but in some versions i've found a "bug"... when searching and "find files" was open and i wanted to listen one *.wav file, and then pressed ESC, it closed "lister" and "search window" at the same time (ESC pushed only once)

In this 10.00 version it's corrected. One push ESC - exits only Lister. Second push ESC - exits search window.

I simply couldn't find what was wrong. could it be a bug in previous (x64) versions?
Post Reply