How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
Moderators: white, Hacker, petermad, Stefan2
-
- Junior Member
- Posts: 13
- Joined: 2019-05-15, 12:23 UTC
How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
Hi,
I regularly copy files to a folder and then rename them to say XXX_panasoinc, XXX_canon, etc.
Take for instance I wanted to rename all the files in the folder to XXX_panasonic. Is there a way whereby I can assign a button to TC such that if I select all the files and press that button, it will automatically append "panasonic" to the end of the original filename? likewise if i wanted to appendix "canon" to the end of the filename, I would select all the files and press the icon that is associated with the Canon button.
Thanks
I regularly copy files to a folder and then rename them to say XXX_panasoinc, XXX_canon, etc.
Take for instance I wanted to rename all the files in the folder to XXX_panasonic. Is there a way whereby I can assign a button to TC such that if I select all the files and press that button, it will automatically append "panasonic" to the end of the original filename? likewise if i wanted to appendix "canon" to the end of the filename, I would select all the files and press the icon that is associated with the Canon button.
Thanks
FAQs: How to process all files in a folder (ForEachSelectedFileDo... .vbs)
Hi fliptoback and welcome.
You can just execute a shell script to do that, TC will aid you with the list of all selected files (or the current folder name / Path)
By the "%F"-parameter, TC will provide a temporary file with each selected items, one per line (Tip: Dir's have got a trailing backslash).
Read on about TC-parameters:
- Right click the button bar to create a new button (Change...).
- In the button dialog click at [Help].
- Scroll down and read at "%L,...... create a list file in the TEMP directory with the names of the selected files and directories,
Or via Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
What to do with those params?:
Now use a tool of your choice to parse the temp file (%F/%L) line-by-line:
VBScript, JavaScript, MS-DOS Batch, AutoHotkey, AutoIt, PascalScript, PowerPro, PowerShell, Python, Perl, Rexx....
The use of already available programming languages is that you can use tools you already know and don't have to learn another language.
Also there can already many script solution be found on the internet which often needs only small adjustements to work with TC too.
The people on this forum mostly use Batch, VBS, AutHotkey and PowerPro.
You can search the forum for the already written 13.263 example or ask for help with some examples what you want to do.
Example temp list, created by "%L":
TC add an trailing backslash on directories:
How to execute an script in TC?:
Such script you can be called from a button, or from a "user defined command" (UDC ; usercmd.ini)
The UDC you can use later as command for a button too, and also can assign a keyboard shortcut to.
Example Total Commander Button code:
'For parameters see > Help "Operation > Menus > Menu Configuration > Change Button Bar > Configuration - Change button bar"
' %L / %F : Create a list file in the TEMP directory with the names of the selected files and directories.
Example PowerShell script, all fits in the button:
TC can provide parameters to get a list of all selected files/folders with or without full path.
So you can mark all files and execute a script which will parse that list
and call an external tool for each line/file or just execute a command, or provide your tool that list if it is able to process that.
- "Get-Content xx | ForEach{ $_ }" is powershell script.
- '%F' is single quoted '..' TC-Parameter and replaced by the path which is set in "quotes" and pointing to the temp file with the filenames.
For parameters see > Help "Operation > Menus > Menu Configuration > Change Button Bar > Configuration - Change button bar"
- "Processing" is just a text used in this test.
- For executing via TC the double quotes "..." for Powershell parameters have to be escaped/masked by using
either \"...\" or tripling them as """...""" (or using single quotes '...' if possible for the current usage)
The same button-code for to Copy&Paste to TCs Buttonbar:
- "Get-Content xx" will read the temp file and put each line/file from it
into the "ForEach{ }"-Loop where your own code waits to do something with that file.
Example external VBS script:
Command: "D:\rive\path to my\ForEachSelFileDo.vbs"
Parameters: "%F"
This are few possibilities only.
- - -
Script examples to loop over the %F/%L file list (w/o your special issue)
Some more code snippets:
Example dos batch script, all fits in the button:
To make it work exchange the ECHO with an more suited command.
Note: Batch works best with basic english ansi/ascii letters only. For umlauts or unicode better use VBS or PoSh.
Or try with another code page like "Parameters: chcp 1252 & FOR /F . . ..... " for windows CP or chcp 65001 for UTF-8 unicode CP
- - -
Example PowerShell script, all fits in the button:
To make it work remove the "-WhatIf" parameter.
- - -
Example external VBScript script, called from the button:
Command: "D:\rive\path to my\ForEachSelFileDo.vbs"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.vbs:
- - -
Powershell -Example
Command: "D:\rive\path to my\ForEachSelFileDo.ps1"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.ps1:
- - -
VBS-Example
Command: "D:\rive\path to my\ForEachSelFileDo.vbs"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.vbs:
- - -
AHK-Example
Command: "D:\rive\path to my\ForEachSelFileDo.ahk"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.ahk:
- - -
MS-DOS Batch Example
Command: "D:\rive\path to my\ForEachSelFileDo.cmd"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.cmd:
Script examples to loop over a provided text file list (w/o your special issue)
Have a plain text file "Your Files list.txt" with file or folder name or whole paths.
Utilize an script to loop over that list and create new, empty zero-byte files or folders.
But how can an script differentiate, if the line contains the name of an folder or an file?
You have to teach him!
Here we take a look if folders in your list have an trailing backslash, then create folder, else create file.
Alternatively we take a look if file in your list have an 3 or 4 signs long extension, then create file, else create folder.
---
PowerShell: create files and folders from text listfile.txt, create FOLDERs if the line from the listfile has trailing backslash (\), else create FILEs :
Get-Content '.\Your Files list.txt'|ForEach{$N=$_-replace":","_";If($N[-1] -eq '\'){MD $N}else{New-Item -Path . -Name "$N" -ItemType "file" -Value "string if wanted"}}
-----------------------
-----------------------
NOTE: MD is short for:
New-Item -Path . -Name "<param>" -ItemType "directory"
-----------------------
---
Or, the other way around:
PowerShell: create files and folders from text listfile.txt, create FILEs if the line from the listfile
has an dot as fourth (.HTM;.JPG) or fifth (.HTML;.JPEG;myFolder.2020\) sign backwards from the end , else create FOLDERs:
Get-Content '.\Files list Dateien liste-1.txt'|ForEach{$N=$_-replace":","_";IF($N[-4..-5] -eq '.'){New-Item -Path . -Name "$N" -ItemType "file" -Value "string if wanted."}else{MD $N}}
-----------------------
-----------------------
To get no error if file/folder already exists, prefix the command by: $ErrorActionPreference = "SilentlyContinue";
Example: $ErrorActionPreference = "SilentlyContinue"; Get-Content '.\Your Files list.txt'|ForEach{ ... }
We can make an button out of this which will work with the selected filelist.txt, or other things if you want.
HTH?
You can just execute a shell script to do that, TC will aid you with the list of all selected files (or the current folder name / Path)
By the "%F"-parameter, TC will provide a temporary file with each selected items, one per line (Tip: Dir's have got a trailing backslash).
Read on about TC-parameters:
- Right click the button bar to create a new button (Change...).
- In the button dialog click at [Help].
- Scroll down and read at "%L,...... create a list file in the TEMP directory with the names of the selected files and directories,
Or via Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
What to do with those params?:
Now use a tool of your choice to parse the temp file (%F/%L) line-by-line:
VBScript, JavaScript, MS-DOS Batch, AutoHotkey, AutoIt, PascalScript, PowerPro, PowerShell, Python, Perl, Rexx....
The use of already available programming languages is that you can use tools you already know and don't have to learn another language.
Also there can already many script solution be found on the internet which often needs only small adjustements to work with TC too.
The people on this forum mostly use Batch, VBS, AutHotkey and PowerPro.
You can search the forum for the already written 13.263 example or ask for help with some examples what you want to do.
Example temp list, created by "%L":
TC add an trailing backslash on directories:
Code: Select all
C:\Windows\Help\en-US\
C:\Windows\Help\en-US\credits.rtf
C:\Windows\Help\mui\0407\cliconf.chm
C:\Windows\Help\mui\0407\mmc.CHM
C:\Windows\Help\mui\0409\
C:\Windows\Help\OEM\ContentStore\
C:\Windows\Help\OEM\IndexStore\
How to execute an script in TC?:
Such script you can be called from a button, or from a "user defined command" (UDC ; usercmd.ini)
The UDC you can use later as command for a button too, and also can assign a keyboard shortcut to.
Example Total Commander Button code:
Code: Select all
Command: "D:\rive\path to my\ForEachSelFileDo.ext"
(or portable Command: "%COMMANDER_PATH%\TOOLs\Scrpts\ForEachSelFileDo.ext")
Parameters: "%F" or "%L" or unicode forms
Start path:
Icon file: WCMICONS.DLL
Tooltip: Script to do smtg with each file from "%F"
' %L / %F : Create a list file in the TEMP directory with the names of the selected files and directories.
Example PowerShell script, all fits in the button:
TC can provide parameters to get a list of all selected files/folders with or without full path.
So you can mark all files and execute a script which will parse that list
and call an external tool for each line/file or just execute a command, or provide your tool that list if it is able to process that.
Code: Select all
Command: PowerShell -NoExit -NoProfile
Parameters: Get-Content '%F' | ForEach{ \"Processing $_\" }
Start path:
Icon file: powershell.exe --or-- WCMICONS.DLL
Tooltip: TEST-Script - ForEachSelectedFileDo...
- '%F' is single quoted '..' TC-Parameter and replaced by the path which is set in "quotes" and pointing to the temp file with the filenames.
For parameters see > Help "Operation > Menus > Menu Configuration > Change Button Bar > Configuration - Change button bar"
- "Processing" is just a text used in this test.
- For executing via TC the double quotes "..." for Powershell parameters have to be escaped/masked by using
either \"...\" or tripling them as """...""" (or using single quotes '...' if possible for the current usage)
The same button-code for to Copy&Paste to TCs Buttonbar:
Code: Select all
TOTALCMD#BAR#DATA
Powershell -NoExit -NoProfile
Get-Content '%F' | ForEach{ \"Processing $_\" }
powershell.exe
TEST-Script - ForEachSelectedFileDo...
-1
into the "ForEach{ }"-Loop where your own code waits to do something with that file.
Example external VBS script:
Command: "D:\rive\path to my\ForEachSelFileDo.vbs"
Parameters: "%F"
Code: Select all
' Total Commander VBScript "ForEachSelectedFileDo -smtg.vbs" by Stefan, 2014-07-24, v0.01
' Found at: https://ghisler.ch/board/viewtopic.php?p=355257#p355257
' Usage:
' 1. Create this script ForEachSelFileDo.vbs as plain text file.
' 2. Create the below button.
' 3. Select some files and click that new button.
'
' TotalCommander Button code:
' Command: "D:\rive\path to my\ForEachSelFileDo.vbs" (or portable: "%COMMANDER_PATH%\TOOLs\VBS\ForEachSelFileDo.vbs")
' Parameters: "%F"
' START:
' ICON: C:\Windows\System32\WScript.exe,2
' TOOLTIP: ForEachSelFileDo VBS
'
'For parameters see > Help > Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar.
' %L / %F : Create a list file in the TEMP directory with the names of the selected files and directories.
If Wscript.arguments.count < 1 Then MsgBox "Error: TC-Param missing..." : WScript.Quit
strTCtempList = Wscript.arguments.Item(0) ' The TC temp file due to the "%L" parameter
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(strTCtempList) Then
Set oTextStream = FSO.OpenTextFile(strTCtempList,1)
Do Until oTextStream.AtEndOfStream
strLine = oTextStream.ReadLine
strNewFilename = replace(strLine,"e","OOOO") '//modifiy the string here
If not (FSO.FileExists(strNewFilename)) Then
MsgBox "Old: " & strLine &vbLF& "New: " & strNewFilename
'//FSO.MoveFile strLine, strNewFilename
End If
Loop
oTextStream.Close
Else
MsgBox "Input file strTCtempList not found. Check button parameter and quoting."_
&vbLF&vbLF & strTCtempList,,"TC-Script Error - ForEachSelFileDo"
End If
This are few possibilities only.
- - -
Script examples to loop over the %F/%L file list (w/o your special issue)
Some more code snippets:
Example dos batch script, all fits in the button:
Code: Select all
Command: cmd /k
Parameters: FOR /F "tokens=*" %%A IN ( ' TYPE "%L" ' ) do @ECHO "%%A"
Start path:
Icon file: WCMICONS.DLL
Tooltip: do something with each line of %L-temp file
Note: Batch works best with basic english ansi/ascii letters only. For umlauts or unicode better use VBS or PoSh.
Or try with another code page like "Parameters: chcp 1252 & FOR /F . . ..... " for windows CP or chcp 65001 for UTF-8 unicode CP
- - -
Example PowerShell script, all fits in the button:
Code: Select all
Command: PowerShell -NoExit -NoProfile
Parameters: Get-Content '%F' | ForEach{ New-Item -Path '%T' -Name "$_" -ItemType "directory" -WhatIf }
Start path:
Icon file: powershell --or-- WCMICONS.DLL
Tooltip: Create selected names in other panel as folders
- - -
Example external VBScript script, called from the button:
Command: "D:\rive\path to my\ForEachSelFileDo.vbs"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.vbs:
Code: Select all
If FSO.FileExists(sTCtempList) Then
Set oTextStream = FSO.OpenTextFile(sTCtempList,FORREADING)
Do Until oTextStream.AtEndOfStream
iCurrFileCount = iCurrFileCount + 1
'//Get basic properties of current file
sFullName = oTextStream.ReadLine '//Ex: "X:\Backup\File.txt"
If(Right(sFullName,1)= "\") Then
Set oItem = FSO.GetFolder(sFullName)
Else
Set oItem = FSO.GetFile(sFullName)
End If
sName = FSO.GetFileName(oItem) '//Ex: "File.txt"
sBase = FSO.GetBaseName(oItem) '//Ex: "File"
sExte = FSO.GetExtensionName(oItem) '//Ex: "txt"
sSize = oItem.Size
sVers = FSO.GetFileVersion(oItem)
sCreated = oItem.DateCreated
sAccessed = oItem.DateLastAccessed
sModified = oItem.DateLastModified
'Attributes: integer value: 0 (Normal), 1 (ReadOnly), 3 (Hidden), 4 (System), 8 (Volume),
'16 (Directory), 32 (Archive), 64 (Alias), and 128 (Compressed). ReadOnly(1) + System(4) + Archive(32) = 37
sAttributes = oItem.Attributes
'MsgBox sFullName &LF& sName &LF& sBase &LF& sExte
'//================================================================================
sDrive = FSO.GetDriveName(oItem) '//Ex: "X:"
sPath = oItem.ParentFolder '//Ex: "X:\Backup"
'//================================================================================
aPathParts = split(sPath, "\")
iUBound = UBound(aPathParts)
sParentFolder1 = aPathParts(iUBound) '//Ex: "Backup"
If (iUBound > 0) Then sParentFolder2 = aPathParts(iUBound -1)
If (iUBound > 1) Then sParentFolder3 = aPathParts(iUBound -2)
If (iUBound > 0) Then sTopFolder1 = aPathParts(1)
If (iUBound > 1) Then sTopFolder2 = aPathParts(2)
If (iUBound > 2) Then sTopFolder3 = aPathParts(3)
'MsgBox sDrive&LF&sPath&LF&iUBound&LF&sParentFolder1&LF&sParentFolder2&LF&sTopFolder2
'//================================================================================
sModified = oItem.DateLastModified '// 16.05.2018 09:20:00 Deutsch German format
sDate = split(sModified," ")(0)
sTime = replace(split(sModified," ")(1),":","")
sDay = split(sDate,".")(0)
sMon = split(sDate,".")(1)
sYer = split(sDate,".")(2)
strTimestamp = sYer &"-"& sMon &"-"& sDay &"-"& sTime
'//================================================================================
'//================================================================================
Powershell -Example
Command: "D:\rive\path to my\ForEachSelFileDo.ps1"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.ps1:
Code: Select all
Cmd=Powershell
Param="%L"
# // Check arguments:
If ($Args.Count -eq 0) { "Please use '%L' as TCs parameter. Also select one or more files first. Script quits here."; return}
# //DEBUG:
# Notepad $Args[0]
# //Do the WORK:
TYPE $Args[0] | ForEach{ ...}
VBS-Example
Command: "D:\rive\path to my\ForEachSelFileDo.vbs"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.vbs:
Code: Select all
sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L"
If FSO.FileExists(sTCtempList) Then
' debug:
WSO.run "notepad " & sTCtempList
Const FORREADING = 1 : Const ForWriting=2 : Const ForAppending=8
Set oTextStream = FSO.OpenTextFile(sTCtempList,FORREADING)
Do Until oTextStream.AtEndOfStream
... do your work here
Loop
oTextStream.Close
Else
WScript.Echo "Input file sTCtempList not found."
End If
AHK-Example
Command: "D:\rive\path to my\ForEachSelFileDo.ahk"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.ahk:
Code: Select all
vTCtempfile=%1%
Loop, Read, %vTCtempfile%
{
vCurrTempFileLine = %A_LoopReadLine%
MsgBox Curr line is:`n%vCurrTempFileLine%
; ... do your work here
}
MS-DOS Batch Example
Command: "D:\rive\path to my\ForEachSelFileDo.cmd"
Parameters: "%F" -- -or "%L" ---or others...
'For parameters see > Help "Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar"
ForEachSelFileDo.cmd:
Code: Select all
@echo off
setlocal enabledelayedexpansion
rem Button Command: cmd /k
rem Button Parameters: "%F" "%P" "%T"
rem path to file list with selected files and folders:
set tc_lst=%1
rem current active source path
set tc_src=%2
rem current active target path
set tc_dst=%3
if -%3==- echo First parameter must be filelist path, second and third - source and target path. && pause && goto :EOF
for /F "usebackq delims=" %%I in (%tc_lst%) do (
rem ============== Insert your custom commands here ==============
echo Exp: %%~I
echo Full Path: %%~fI
echo LW: %%~dI
echo Path: %%~pI
echo File Name: %%~nI
echo Extension: %%~xI
echo ShortPath: %%~sI
echo Attrb: %%~aI
echo Date Time: %%~tI
echo Size: %%~zI
echo ----------------------------
rem ==============================================================
)
pause
cls
endlocal
Script examples to loop over a provided text file list (w/o your special issue)
Have a plain text file "Your Files list.txt" with file or folder name or whole paths.
Utilize an script to loop over that list and create new, empty zero-byte files or folders.
But how can an script differentiate, if the line contains the name of an folder or an file?
You have to teach him!
Here we take a look if folders in your list have an trailing backslash, then create folder, else create file.
Alternatively we take a look if file in your list have an 3 or 4 signs long extension, then create file, else create folder.
---
PowerShell: create files and folders from text listfile.txt, create FOLDERs if the line from the listfile has trailing backslash (\), else create FILEs :
Get-Content '.\Your Files list.txt'|ForEach{$N=$_-replace":","_";If($N[-1] -eq '\'){MD $N}else{New-Item -Path . -Name "$N" -ItemType "file" -Value "string if wanted"}}
-----------------------
Code: Select all
Get-Content '.\Your Files list.txt'|
ForEach{
$N=$_-replace":","_";
If($N[-1] -eq '\'){
MD $N
}else{
New-Item -Path . -Name "$N" -ItemType "file" -Value "This is a text string."
}
}
NOTE: MD is short for:
New-Item -Path . -Name "<param>" -ItemType "directory"
-----------------------
---
Or, the other way around:
PowerShell: create files and folders from text listfile.txt, create FILEs if the line from the listfile
has an dot as fourth (.HTM;.JPG) or fifth (.HTML;.JPEG;myFolder.2020\) sign backwards from the end , else create FOLDERs:
Get-Content '.\Files list Dateien liste-1.txt'|ForEach{$N=$_-replace":","_";IF($N[-4..-5] -eq '.'){New-Item -Path . -Name "$N" -ItemType "file" -Value "string if wanted."}else{MD $N}}
-----------------------
Code: Select all
Get-Content '.\Your Files list.txt'|
ForEach{
$N=$_-replace":","_";
IF($N[-4..-5] -eq '.'){
New-Item -Path . -Name "$N" -ItemType "file" -Value "This is a text string."
}else{
MD $N
}
}
To get no error if file/folder already exists, prefix the command by: $ErrorActionPreference = "SilentlyContinue";
Example: $ErrorActionPreference = "SilentlyContinue"; Get-Content '.\Your Files list.txt'|ForEach{ ... }
We can make an button out of this which will work with the selected filelist.txt, or other things if you want.
HTH?
-
- 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
Thanks Stefan. I will try that and report back. Cheers for the reply ![Smile :)](./images/smilies/icon_smile.gif)
![Smile :)](./images/smilies/icon_smile.gif)
Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
You can also use a saved Multi-Rename Tool setting:
1. open the Multi-Rename Tool (Ctrl+M)
2. In the "Rename mask" field type [N]_Panasonic
3. Press F2 to save the settings - call it Panasonic.
4. Close the Multi-Rename Tool.
5. Make this button:
1. open the Multi-Rename Tool (Ctrl+M)
2. In the "Rename mask" field type [N]_Panasonic
3. Press F2 to save the settings - call it Panasonic.
4. Close the Multi-Rename Tool.
5. Make this button:
Code: Select all
TOTALCMD#BAR#DATA
MULTIRENAME Panasonic
wcmicons.dll,46
Multi Rename Tool - Panasonic
-1
Now you can open the Multi-Rename Tool with the Panasonic setting with this button - then you only have to click the Start! button.To make the button:
1. Mark the green text above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
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
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
-
- 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
Wow thanks Stefan. That is great. I see that this is someform of vbscript..is the script files limited to using vbscript? I am not familiar with VB unfortunately.Stefan2 wrote: ↑2019-05-15, 13:42 UTCCode: Select all
' Total Commander VBScript "ForEachSelectedFileDo -smtg.vbs" by Stefan, 2014-07-24, v0.01 ' Found at: https://ghisler.ch/board/viewtopic.php?p=355257#p355257 ' Usage: ' 1. Create this script ForEachSelFileDo.vbs as plain text file. ' 2. Create the below button. ' 3. Select some files and click that new button. ' ' TotalCommander Button code: ' CMD: "D:\rive\path to my\ForEachSelFileDo.vbs" (or portable: "%COMMANDER_PATH%\TOOLs\VBS\ForEachSelFileDo.vbs") ' PARAM: "%F" ' START: ' ICON: C:\Windows\System32\WScript.exe,2 ' TOOLTIP: ForEachSelFileDo VBS ' 'For parameters see > Help > Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar. ' %L / %F : Create a list file in the TEMP directory with the names of the selected files and directories. If Wscript.arguments.count < 1 Then MsgBox "Error: TC-Param missing..." : WScript.Quit strTCtempList = Wscript.arguments.Item(0) ' The TC temp file due to the "%L" parameter Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FileExists(strTCtempList) Then Set oTextStream = FSO.OpenTextFile(strTCtempList,1) Do Until oTextStream.AtEndOfStream strLine = oTextStream.ReadLine strNewFilename = replace(strLine,"e","OOOO") '//modifiy the string here If not (FSO.FileExists(strNewFilename)) Then MsgBox "Old: " & strLine &vbLF& "New: " & strNewFilename '//FSO.MoveFile strLine, strNewFilename End If Loop oTextStream.Close Else MsgBox "Input file strTCtempList not found. Check button parameter and quoting."_ &vbLF&vbLF & strTCtempList,,"TC-Script Error - ForEachSelFileDo" End If
This is one possibility only.
-
- 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
Now this is new for me and I have been using TC for like 15 years if not more. I have never realized that you can save the multi-rename settings! Cool bananas.petermad wrote: ↑2019-05-15, 16:45 UTC You can also use a saved Multi-Rename Tool setting:
1. open the Multi-Rename Tool (Ctrl+M)
2. In the "Rename mask" field type [N]_Panasonic
3. Press F2 to save the settings - call it Panasonic.
4. Close the Multi-Rename Tool.
5. Make this button:Code: Select all
TOTALCMD#BAR#DATA MULTIRENAME Panasonic wcmicons.dll,46 Multi Rename Tool - Panasonic -1
Now you can open the Multi-Rename Tool with the Panasonic setting with this button - then you only have to click the Start! button.To make the button:
1. Mark the green text above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
No.
TC just provides a temporary file with each selected items, one per line (Tip: Dir's have got a trailing backslash).
'For parameters see > Help > Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar.
' %L / %F : Create a list file in the TEMP directory with the names of the selected files and directories.
Now use a tool of your choice to parse the temp file line-by-line: VBScript, JavaScript, MS-DOS Batch, AutoHotkey, AutoIt, PascalScript, PowerPro, PowerShell, Python, Perl, Rexx....
The people on this forum mostly use Batch, VBS, AutHotkey and PowerPro.
HTH?
Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
2fliptoback
You can also incorporate A DOS script like this directly in the button:
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.
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
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
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
Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
fliptoback,
A quick and dirty AHK solution:
As parameters in the Button Bar use:
HTH
Roman
A quick and dirty AHK solution:
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]
Code: Select all
"%L" _panasonic
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.
-
- 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
Hi, I tried out this script. Works well. But is it possible to program this such that when i select the files, press the panasonic button and voila it will rename automatically without me pressing the "start!" button? At the moment it will pop up the Multi-Rename tool and i have to press the start! button manually. Thanks!fliptoback wrote: ↑2019-05-16, 00:05 UTCNow this is new for me and I have been using TC for like 15 years if not more. I have never realized that you can save the multi-rename settings! Cool bananas.petermad wrote: ↑2019-05-15, 16:45 UTC You can also use a saved Multi-Rename Tool setting:
1. open the Multi-Rename Tool (Ctrl+M)
2. In the "Rename mask" field type [N]_Panasonic
3. Press F2 to save the settings - call it Panasonic.
4. Close the Multi-Rename Tool.
5. Make this button:Code: Select all
TOTALCMD#BAR#DATA MULTIRENAME Panasonic wcmicons.dll,46 Multi Rename Tool - Panasonic -1
Now you can open the Multi-Rename Tool with the Panasonic setting with this button - then you only have to click the Start! button.To make the button:
1. Mark the green text above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctri+C).
3. Right click on TC's buttonbar and choose "Paste".
-
- 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
Thanks for that info. I am only vaguely familiar with batch and autoIt but you mentioned PascalScript. I used to do a bit of pascal when i was at school so i will look into that one.Stefan2 wrote: ↑2019-05-16, 07:28 UTC
No.
TC just provides a temporary file with each selected items, one per line (Tip: Dir's have got a trailing backslash).
'For parameters see > Help > Operation > Menus > Menu: Configuration > Change Button Bar > Configuration - Change button bar.
' %L / %F : Create a list file in the TEMP directory with the names of the selected files and directories.
Now use a tool of your choice to parse the temp file line-by-line: VBScript, JavaScript, MS-DOS Batch, AutoHotkey, AutoIt, PascalScript, PowerPro, PowerShell, Python, Perl, Rexx....
The people on this forum mostly use Batch, VBS, AutHotkey and PowerPro.
HTH?
-
- 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
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.petermad wrote: ↑2019-05-16, 10:42 UTC 2fliptoback
You can also incorporate A DOS script like this directly in the button: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.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
-
- 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
Thanks. I installed AHK and now copied/pasted the first part of the code into the script. But I can't seem to able to paste into the toolbar to create the button?Hacker wrote: ↑2019-05-16, 11:07 UTC fliptoback,
A quick and dirty AHK solution:As parameters in the Button Bar use: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]
HTHCode: Select all
"%L" _panasonic
Roman
Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
Only some small script (mostly batch and PoSh) can be used directly in an button,fliptoback wrote: ↑2019-05-16, 12:57 UTC...
But I can't seem to able to paste into the toolbar to create the button?
for all others write the code to a plain text file and call that from the button:
Total Commander Button code:
Code: Select all
Command: "D:\rive\path to my\ForEachSelFileDo.ext" (or portable: "%COMMANDER_PATH%\TOOLs\Scrpts\ForEachSelFileDo.ext")
Parameters: "%F" or "%L" or unicode forms
Start path: mostly always empty
Icon file: WCMICONS.DLL or the used interpreter.exe
Tooltip: Script to do smtg with each file from "%F"
And only code which starts with a " TOTALCMD#BAR#DATA "-line are directly button-code for to paste onto the buttonbar.
If you like, read on there >> viewtopic.php?f=3&t=52425&p=354622#p354622
Re: How to create a button to bulk rename all files in a folder and append a fixed sequence to the files
fliptoback,
HTH
Roman
Try e.g.:I can't seem to able to paste into the toolbar to create the button?
Code: Select all
TOTALCMD#BAR#DATA
C:\Scripts\AppendFileName.ahk
"%L" _panasonic
C:\Program Files\AutoHotkey\AutoHotkey.exe,1
Append "_panasonic"
-1
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.