How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

English support forum

Moderators: white, Hacker, petermad, Stefan2

User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *petermad »

fliptoback wrote: 2019-05-16, 12:48 UTC
petermad wrote: 2019-05-16, 10:42 UTC 2fliptoback
You can also incorporate A DOS script like this directly in the button:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo•) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wciconex.dll,32
Add "_Panasonic" to selected filenames


-1
You will get a beep if you have not selected at least one file or if you are trying to run the script from a place where DOS does not work - like inside Archives, FTP sites or Virtual panels. It works with Unicode file names, and for hidden and system files - BUT the hidden/system file attributes will be removed.
Hmm..I could not get this to work. I copied the code, and right click at the menubar and press paste. it created the button but when i select the files and pressed it, it run the batch file but did not change any filenames.
Hmm, it works OK here Both under WIndows 7 and 10. Are you running the script on a network share? - it might not work there.

BTW - if you get it to work, and you don't want to see the DOS window popping up use this in stead:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo•) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wciconex.dll,32
Add "_Panasonic" to selected filenames

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
User avatar
Horst.Epp
Power Member
Power Member
Posts: 6429
Joined: 2003-02-06, 17:36 UTC
Location: Germany

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Horst.Epp »

fliptoback wrote: 2019-05-16, 12:48 UTC
petermad wrote: 2019-05-16, 10:42 UTC 2fliptoback
You can also incorporate A DOS script like this directly in the button:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo•) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wciconex.dll,32
Add "_Panasonic" to selected filenames


-1
You will get a beep if you have not selected at least one file or if you are trying to run the script from a place where DOS does not work - like inside Archives, FTP sites or Virtual panels. It works with Unicode file names, and for hidden and system files - BUT the hidden/system file attributes will be removed.
Hmm..I could not get this to work. I copied the code, and right click at the menubar and press paste. it created the button but when i select the files and pressed it, it run the batch file but did not change any filenames.
Works perfect here
Windows 11 Home x64 Version 23H2 (OS Build 22631.3296)
TC 11.03 x64 / x86
Everything 1.5.0.1371a (x64), Everything Toolbar 1.3.2, Listary Pro 6.3.0.69
QAP 11.6.3.2 x64
fliptoback
Junior Member
Junior Member
Posts: 13
Joined: 2019-05-15, 12:23 UTC

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *fliptoback »

Hacker wrote: 2019-05-16, 13:19 UTC fliptoback,
I can't seem to able to paste into the toolbar to create the button?
Try e.g.:

Code: Select all

TOTALCMD#BAR#DATA
C:\Scripts\AppendFileName.ahk
"%L" _panasonic
C:\Program Files\AutoHotkey\AutoHotkey.exe,1
Append "_panasonic"


-1
HTH
Roman
Thanks Roman. I must be doing something wrong. this is what i did.

I created the AHK file (filename = renamepana1.ahk and saved this in c:\totalcmd\tools\scripts folder) with the content as follows:

Code: Select all

SetWorkingDir, %A_ScriptDir%
FileRead, FileList, % A_Args[1]
FileList := SubStr(FileList, 1, -2)
Loop, Parse, FileList, `n, `r
	FileMove, % A_LoopField, % InStr(A_LoopField, ".") ? SubStr(A_LoopField, 1, InStr(A_LoopField, ".", , 0) - 1) . A_Args[2] . SubStr(A_LoopField, InStr(A_LoopField, ".", , 0)) : A_LoopField . A_Args[2]
Then I created the following text in a text editor

Code: Select all

TOTALCMD#BAR#DATA
c:\totalcmd\Tools\scripts\renamepana1.ahk
"%L" _pana1
C:\Program Files\AutoHotkey\AutoHotkey.exe,1
Append "_pana1"


-1
and then copy this section of the text, right click on Totalcommander toolbar and select paste.

But when i select the files i want to rename, pressing the newly created button simply load up the AHK file in the text editor. It does not do anything else.

I know this is not what it should be but i am at a loss.
User avatar
Stefan2
Power Member
Power Member
Posts: 4124
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Stefan2 »

Doesn't work for me with 9.22a on win10

>> "if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo•)"

- First error: unknown command "echo•"
- After fix, i get only a "•" in the console (tested with cmd /k), nothing else

- - -

The shorted rest works for me:
chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"

Code: Select all

TOTALCMD#BAR#DATA
CMD /k
chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && CMD /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wciconex.dll,32
Add "_Panasonic" to selected filenames


-1


 
User avatar
Stefan2
Power Member
Power Member
Posts: 4124
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Stefan2 »

fliptoback wrote: 2019-05-16, 14:37 UTC...
Thanks Roman. I must be doing something wrong. this is what i did.
...

That depends on how you utilize AutoHotkey,.... installed (".AHK" should be a well know extension now) or portable.



You don't need to install AHK, just put the AutoHotkey.exe with his files into an folder (best, a sub folder of TC?) and use AHK portable:
AutoHotkey.exe myScript.ahk


So try this instead:

----------------------------------------------------------
TOTALCMD#BAR#DATA
"C:\Program Files\AutoHotkey\AutoHotkey.exe" c:\totalcmd\Tools\scripts\renamepana1.ahk
"%L" _pana1
C:\Program Files\AutoHotkey\AutoHotkey.exe,1
Append "_pana1"


-1
----------------------------------------------------------



 
fliptoback
Junior Member
Junior Member
Posts: 13
Joined: 2019-05-15, 12:23 UTC

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *fliptoback »

Thanks Stefan and Roman for the help. I am using 9.21a x64 if that matters. I am going to reinstall AHK tomorrow and see if this helps. I will sign off now to get some sleep and will try again tomorrow. I am still dead keen to resolve this one.
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *petermad »

2Stefan2
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo•)
The first part is to test that you are on a drive that DOS can handle, the second part is to test that at least one file is actually selected (not just the with the cursor on it) or if the cursor is on a folder. Apparently your OS's cannot handle the echo• which at my systems gives me a beep sound.

The reason for the message is a missing space after echo. But if you try the button in a panel that shows a normal harddisk folder, and if at least one file is selected - the the echo command should not be executed at all.

Maybe there is a Registry setting for cmd.exe that prevents it from handling control characters - but I haven't made any changes to my system for cmd.exe.

Please try either this in a normal harddisk folder (USB drive with drive letter will also do) with at least one selected file, and with no selected file (should give beep):

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo •) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wcmicons.dll,32
Add "_Panasonic" to selected filenames

1
-1
or this:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo.•) else if exist %Y%P%S1\ (echo.•) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wcmicons.dll,32
Add "_Panasonic" to selected filenames

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
fliptoback
Junior Member
Junior Member
Posts: 13
Joined: 2019-05-15, 12:23 UTC

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *fliptoback »

petermad wrote: 2019-05-16, 18:42 UTC 2Stefan2
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo•)
The first part is to test that you are on a drive that DOS can handle, the second part is to test that at least one file is actually selected (not just the with the cursor on it) or if the cursor is on a folder. Apparently your OS's cannot handle the echo• which at my systems gives me a beep sound.

The reason for the message is a missing space after echo. But if you try the button in a panel that shows a normal harddisk folder, and if at least one file is selected - the the echo command should not be executed at all.

Maybe there is a Registry setting for cmd.exe that prevents it from handling control characters - but I haven't made any changes to my system for cmd.exe.

Please try either this in a normal harddisk folder (USB drive with drive letter will also do) with at least one selected file, and with no selected file (should give beep):

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo •) else if exist %Y%P%S1\ (echo •) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wcmicons.dll,32
Add "_Panasonic" to selected filenames

1
-1
or this:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo.•) else if exist %Y%P%S1\ (echo.•) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wcmicons.dll,32
Add "_Panasonic" to selected filenames

1
-1
Thanks Peter. I am so glad both of these work for me! Not sure why things dont work before! Very happy. Thanks again Pete.
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *petermad »

2fliptoback
Glad to hear that it works now :D
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
User avatar
Stefan2
Power Member
Power Member
Posts: 4124
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Stefan2 »

"(echo•)" and "(echo •)" or "(echo.•)" still doesn't work as expected on my win10. Even not with an selected file.
But tested on win7 I can hear the peep and the command works as original posted.



over and out
User avatar
Usher
Power Member
Power Member
Posts: 1675
Joined: 2011-03-11, 10:11 UTC

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Usher »

2Stefan2
There should be 0x07 character (BELL) there: https://en.wikipedia.org/wiki/Bell_character
The bullet should be converted from Unicode to ASCII: https://devblogs.microsoft.com/oldnewthing/20070104-00/?p=28513
Do you save the file using the same codepage and have the same codepage in console on both systems? Have you tested echo directly in cmd window?

That way the computer should make beep using internal PC speaker, but in modern computers it is usually redirected to the sound card, so beep may depend on bios settings, sound card drivers and sound (mixer) settings. Do you use both systems on the same PC? PC speaker as a legacy device might be turned off by default when Microsoft changed mixer in Windows 10, but it should be possible to enable Win7 mixer, see search results:
https://www.google.com/search?q+sound+mixer+in+windows+10
Andrzej P. Wozniak
Polish subforum moderator
User avatar
Stefan2
Power Member
Power Member
Posts: 4124
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Stefan2 »

2Usher

Thank you Andrzej, but I didn't need that myself, ...just wanted to tell, that that may not work always for everyone.


Me tested on w7 with an older ASUS Laptop and on w10 on a newer DELL OptiPlex 7040, a modern mini pc.

And sorry, no really time to investigate, and as it doesn't matter for my self.... ;-)




 
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *petermad »

I checked a bit more. If I execute echo • in a DOS console under Windows XP and Window 7 I get a generic beep sound. If I do it in Windows 8.1 I get the sound that is assigned for Windows' "Critical error". In windows 10 the • is displayed in the DOS console, but if I redirect to console with: "echo • > con" I get the same sound as in Windows 8.1.

If I use %COMSPEC% /K in the button and echo • > con - I do get the beep when using the button under Windows 8.1 and 10, but if I use %COMSPEC% /C I don't get the beep - apparently the DOS console is closed before the beep is carried out (maybe because my windows 8.1 and 10 computers are slow).

But no matter what, the echo • should not matter if the condition that should trigger it is not met - that is we are on a DOS supported drive and there is at least one file selected, then the two first if's are false and the files should be renamed. Anyway that is what I experience under Windows 10.

2Stefan2
How about this:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /C
if not exist "%P" (echo • > con) else if exist %Y%P%S1\ (echo • > con) else chcp 65001 && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do attrib -H -S "%%n" && %%COMSPEC%% /C for /F "usebackq delims=" %%n in (`type %WL`) do if not exist "%%n\*" ren "%%n" "%%~nn_Panasonic%%~xn"
wcmicons.dll,32
Add "_Panasonic" to selected filenames

1
-1
does that work on your Windows 10 ?
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
User avatar
Stefan2
Power Member
Power Member
Posts: 4124
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *Stefan2 »

petermad wrote: 2019-05-17, 16:10 UTC...

2Stefan2
How about this:
---

does that work on your Windows 10 ?

Sorry, I get only access to w10 on Monday....


:thumbsup:




 
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files

Post by *petermad »

2Stefan2
Sorry, I get only access to w10 on Monday....
No problem :-)
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
Post Reply