brian,
TCs parameter "%L" (use quotes) provides path to temp file with all selected file names.
(right click an button, chose "Change...", press F1 key and read the help for more)
Use "%L" as parameter for your script "MyScript.vbs":
CMD = "path to\MyScript.vbs"
PARAM= "%L"
to process each selected file.
"MyScript.vbs" contains for example:
Code: Select all
'// ===========================================================
'// VBScript for Total Commander, by Stefan
'// _ForEachSelFileDo.vbs, Version 16.0228, 2016-02-28
'// Forum: http://ghisler.ch/board/viewtopic.php?p=323561#323561
'// Purpose:
'// Example:
'//
'// TC Button:
'// CMD: "D:\rive\path\to this\MyScript.vbs"
'// PARAM: "%L"
'// USAGE: Scroll down to "UserWorkHere" and add your code.
'// Select your files, execute this script... done.
'// ===========================================================
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
If (Wscript.arguments.count < 1) Then
MsgBox "Please use from TC with parameter like '%L'",,"VBScript - ERROR"
WScript.Quit
Else
sTCtempList = Wscript.arguments.Item(0) ' The TC temp file due the "%L"
End If
If FSO.FileExists(sTCtempList) Then
Set oTextStream = FSO.OpenTextFile(sTCtempList,ForReading)
sFileContent = oTextStream.ReadAll
oTextStream.Close
aLineArray = split(sFileContent,vbCRLF)
'// =================== For each line in TCs temp list, Do your work:
For i=0 To UBound(aLineArray) -1
Set oItem = FSO.GetFile(aLineArray(i)) '//Ex: "X:\Work\Orders\File.txt"
sPath = oItem.ParentFolder '//Ex: "X:\Work\Orders"
sPath = sPath & "\" '//Ex: "X:\Work\Orders\"
sOldName = FSO.GetFileName(oItem) '//Ex: "File.txt"
sBase = FSO.GetBaseName(oItem) '//Ex: "File"
sExte = FSO.GetExtensionName(oItem) '//Ex: "txt"
'// ################################################################## UserWorkHere:
'// DO YOUR WORK HERE (For each line in TCs temp list):
sNewName = Replace(sOldName, "a","X")
sNewName = Replace(sNewName, "e","Y")
sNewName = Replace(sNewName, "o","A")
'D:\ForEachSelFileDo.vbs
'D:\ForEXchSYlFilYDA.vbs
MsgBox sPath & sOldName & vbLF & sPath & sNewName
If NOT (FSO.FileExists(sPath & sNewName)) Then
'//Command disabled by comment sign ' :
'FSO.MoveFile sPath & sOldName, sPath & sNewName
Else
End If
'// DO YOUR WORK ABOVE.
'// ##################################################################
Next
Else
MsgBox "Input file 'sTCtempList' (%L) not found OR no selection done before.",,"TCs-VBScript - ERROR"
WScript.Quit
End If
All you need to do is:
- save the code as "MyScript.vbs"
- modify the "DO YOUR WORK HERE" part (ask if you need help)
- create a TC Button:
CMD: "D:\rive\path\to this\MyScript.vbs"
PARAM: "%L"
- select the files (utilize Branch View first to process sub folders)
- press the button to execute the script
There are more examples >>
http://ghisler.ch/board/viewtopic.php?p=305571#305571
I need to add this topic to my FAQs >>
http://ghisler.ch/board/viewtopic.php?p=287481#287481