Sysin wrote: 2019-06-10, 05:59 UTC
Stefan,
i would like to ask You for one more think.
Its working nicely, but when in target Folder name is used "space" it is not working and it saying "path wasnt found; row 26"
It is possible do something with it?
Do you really use space around parameters in Button? > "%T"
' TotalCommander Button code:
' CMD: "%COMMANDER_PATH%\TOOLs\VBS\ForEachSelFileDo.vbs"
' PARAM: "%F" "%T"
' START:
' ICON: C:\Windows\System32\WScript.exe,2
' TOOLTIP: ForEachSelFileDo VBS
Sysin wrote:Also put there Yes to all
Sorry, a "[Yes to all]" directly is not really possible, only with workaround and not really fitting button description.
But I have adjusted the code for the debug part.
That message should only appear "iDebugAmount" of time now (5 times on default).
Sysin wrote:
and finally if it can search also subfolders.
See TC menu "Command" and utilize "Branch View" first.
But I don't know yet if that will help you.
Sysin wrote:
P.S. Still own You some beers so give me Your paypal acc.(mail, to PM)
Thank you very much, but no need for that

Just do you help two others too and that's all, ok?
Here is the adjusted code, hope it works, can only test tomorrow (and I must think on PeterMad and test something on w10 too)
Code: Select all
' VBS-Script to use with TotalCommander.
' _ForEachSelFileDo - x.vbs
' Found at: https://ghisler.ch/board/viewtopic.php?p=356094#p356094
' Version 3 , 2019-06-10 Mon 18:33:42
' Purpose:
' Usage: Save script as plain text with VBS-extension in TC-folder.
' Create the button, have Source and Target folder open in panels, click the button, done.
'
' TotalCommander Button code:
' CMD: "%COMMANDER_PATH%\TOOLs\VBS\ForEachSelFileDo.vbs"
' PARAM: "%F" "%T"
' START:
' ICON: C:\Windows\System32\WScript.exe,2
' TOOLTIP: ForEachSelFileDo VBS
'
If (Wscript.arguments.count < 1) Then
MsgBox "Please use from TC with parameter like '%F' '%T'",,"VBScript - ERROR"
WScript.Quit
Else
sTCtempList = Wscript.arguments.Item(0) ' The selected files in TC Active panel due to the "%F" parameter
sTC_T = Wscript.arguments.Item(1) ' The Target panel due to the "%T" parameter
End If
'//DEBUG: Show debug messagebox?
bDebugMsg=true
'//DEBUG: Show debug messagebox this many times, next continue with all files:
iDebugAmount=2
'//DEBUG: stop at this maximal amount of files processed:
iMAXFileCount=10
SET FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(sTCtempList) Then
Set oFolder_T = FSO.GetFolder(sTC_T)
Set colFiles_T = oFolder_T.Files
Set oTextStream = FSO.OpenTextFile(sTCtempList,1)
Do Until oTextStream.AtEndOfStream
iCurrFileCount = iCurrFileCount + 1
sFullName = oTextStream.ReadLine
If(Right(sFullName,1) <> "\") Then
Set oFileA = FSO.GetFile(sFullName)
sNameA = oFileA.Name
sSizeA = oFileA.Size
CD = oFileA.DateCreated
AD = oFileA.DateLastAccessed
MD = oFileA.DateLastModified
sSourcePath = oFileA.ParentFolder
For Each oFileT in colFiles_T
sSizeT = oFileT.Size
If (sSizeT = sSizeA) Then
sNameT = oFileT.Name
sTargetPath = oFileT.ParentFolder
If(bDebugMsg AND (iCurrFileCount <= iDebugAmount)) Then
MB = MsgBox( "Found a buddy !"&vbLF&vbLF&"Source: "&sNameA&vbLF&"Buddy : "&sNameT&vbLF&vbLF _
&"Copy "&sNameT&" to Source folder,"&vbLF&"next rename "&sNameT&" to "&sNameA&vbLF _
&" and copy also the timestamp: [Yes]/[No]?"&vbLF&vbLF _
&vbLF&"(You will see '" & iDebugAmount &"' of such Messages, next all files will be processed)"&vbLF&vbLF _
&vbLF&"[Cancel] to stop the whole script." , VBYesNoCancel+vbQuestion,"Total Commander VBScript")
If (MB = vbYes) Then bDoIt = True
If (MB = vbCancel) Then WScript.Quit
Else
bDoIt = True
End If
If(bDoIt) Then
If(FSO.FileExists(sSourcePath &"\__DEL_"&sNameA)=False) Then
FSO.CopyFile sTargetPath&"\"&sNameT, sSourcePath&"\"&sNameA&"_NEW", False 'True=überschreiben
ReDateFile sSourcePath&"\"&sNameA&"_NEW", MD
'FSO.DeleteFile(sSourcePath&"\"&sNameA)
FSO.MoveFile sSourcePath&"\"&sNameA, sSourcePath&"\__DEL_"&sNameA
FSO.MoveFile sSourcePath&"\"&sNameA&"_NEW", sSourcePath&"\"&sNameA
Else
' MsgBox " Double ? Will skip. Already existent: " & vbLF & "__DEL_"&sNameA
End If
End If '(bDoIt)
End If 'same size
Next
If(iCurrFileCount = iMAXFileCount) Then Exit Do
End If 'file or folder
Loop 'do
oTextStream.Close
MsgBox "All "&iCurrFileCount&" Done."&vbLF& iSkip &" found as double and so skipped." _
& vbLF&"(You can now delete the old files starting now with '__DEL_')"
Else
MsgBox "E R R O R:"&vbLF&vbLF&"Input file 'sTCtempList' (%L or &F) not found"_
&vbLF&vbLF&"OR no selection done before.",,"TCs-VBScript - ERROR"
WScript.Quit
End If
Sub ReDateFile(strPath, strDateMod)
Set app = CreateObject("Shell.Application")
par = FSO.GetParentFolderName(strPath)
Set folder = app.NameSpace(par)
fil = FSO.GetFileName(strPath)
Set ofile = folder.ParseName(fil)
ofile.ModifyDate = CDate(strDateMod)
End Sub