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: Stefan2, white, sheep, Hacker

User avatar
petermad
Power Member
Power Member
Posts: 8422
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, 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 » 2019-05-16, 13:33 UTC

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 9.22a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1903) 64bit, 'Everything' 1.4.1.935 (x64)
TC 3.0b5 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

User avatar
Horst.Epp
Power Member
Power Member
Posts: 3375
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 » 2019-05-16, 13:39 UTC

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 10 Home x64 May 2019 Update, Version 1903 (OS Build 18362.295)
Intel(R) Core(TM) i7-4770 CPU @ 3.40GH, 16GB RAM
TC 9.22a x64 and x86, Everything 1.4.1.947 (x64)

fliptoback
Junior Member
Junior Member
Posts: 11
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 » 2019-05-16, 14:37 UTC

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: 2551
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 » 2019-05-16, 14:40 UTC

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


 
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

User avatar
Stefan2
Power Member
Power Member
Posts: 2551
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 » 2019-05-16, 14:44 UTC

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
----------------------------------------------------------



 
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

fliptoback
Junior Member
Junior Member
Posts: 11
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 » 2019-05-16, 14:50 UTC

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: 8422
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, 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 » 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
License #524 (1994)
Danish Total Commander Translator
TC 9.22a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1903) 64bit, 'Everything' 1.4.1.935 (x64)
TC 3.0b5 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

fliptoback
Junior Member
Junior Member
Posts: 11
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 » 2019-05-16, 23:28 UTC

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: 8422
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, 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 » 2019-05-17, 01:03 UTC

2fliptoback
Glad to hear that it works now :D
License #524 (1994)
Danish Total Commander Translator
TC 9.22a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1903) 64bit, 'Everything' 1.4.1.935 (x64)
TC 3.0b5 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

User avatar
Stefan2
Power Member
Power Member
Posts: 2551
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 » 2019-05-17, 07:13 UTC

"(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
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

User avatar
Usher
Senior Member
Senior Member
Posts: 408
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 » 2019-05-17, 13:51 UTC

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
Regards from Poland
Andrzej P. Wozniak

User avatar
Stefan2
Power Member
Power Member
Posts: 2551
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 » 2019-05-17, 14:23 UTC

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.... ;-)




 
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

User avatar
petermad
Power Member
Power Member
Posts: 8422
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, 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 » 2019-05-17, 16:10 UTC

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 9.22a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1903) 64bit, 'Everything' 1.4.1.935 (x64)
TC 3.0b5 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

User avatar
Stefan2
Power Member
Power Member
Posts: 2551
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 » 2019-05-17, 18:36 UTC

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:




 
Inofficial FAQs || WIKI (Deu/Eng) || TC Home (What's new? // FAQ // Download // Order // Addons // Tools // Plugins)
Erst wenn der letzte Baum gefällt oder die letzte Biene verendet ist, werden die Leute verstehen warum Umweltschutz wichtig ist.

User avatar
petermad
Power Member
Power Member
Posts: 8422
Joined: 2003-02-05, 20:24 UTC
Location: Valsted, 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 » 2019-05-17, 21:47 UTC

2Stefan2
Sorry, I get only access to w10 on Monday....
No problem :-)
License #524 (1994)
Danish Total Commander Translator
TC 9.22a 32+64bit on Win XP 32bit, Win 7, 8.1 & 10 (1903) 64bit, 'Everything' 1.4.1.935 (x64)
TC 3.0b5 on Android 6.0
Get: Extended Total Commander Menus | PHSM-Calendar

Post Reply