jesped wrote: 2023-11-21, 04:30 UTC
Is there a way for Total Commander to replace files in a folder tree with an updated version?
Let's say I want to automatically update a Reshade shader with the new version in all the subfolders of my C:\Games where that file already exists...
or update the nvngx_dlss.dll Nvidia DLSS library...
You may want to try PowerShell or VBS:
This script will do:
- For each sub-folder / and there for each file ...
- If FileName = sItem Then
- - - GetParentFolderName
- - - Copy "sItem" to "ParentFolderName\sItem , overwrite existing: true
- End If
STEPS:
-- save this script as "something.VBS".
-- copy this VBS to the wanted top-main-folder.
-- have the "sitem" in that folder with the VBS too.
-- adjust
oStartFolder = "." ' dot=current folder (
try with an TEST folder and with a few sub folders and files first)
sItem = "shader.exe" 'Name of the file to find and name of the file to copy (must be in same folder as this script, else we had to adjust this script)
-- double click the VBS to execute it.
Code: Select all
'----------------------
' 2023-11-22 by Stefan
' Replace a file in a folder tree with an updated version?
' https://ghisler.ch/board/viewtopic.php?p=445580#p445580
'
' This script will do:
' - For each sub-folder / and there for each file ...
' - If FileName = sItem Then
' - - - GetParentFolderName of sItem
' - - - Copy "sItem" to "ParentFolderName\sItem" , overwrite existing: true
' - End If
'
'STEPS:
'-- save this script as "something.VBS".
'-- copy this VBS to the wanted top-main-folder.
'-- have the "sitem" in that folder with the VBS too.
'-- adjust
'oStartFolder = "." ' dot=current folder (try with an TEST folder and with a few sub folders and files first)
'sItem = "shader.exe" 'Name of the file to find and name of the file to copy (must be in same folder as this script, else we had to adjust this script)
'-- double click the VBS to execute it.
'----------------------
Set oFSO = CreateObject("Scripting.FileSystemObject")
'----------------------
' User Settings
'// the folder to work in:
'oStartFolder = "C:\Work\2023" '(try with an TEST folder and with a few sub folders and files first)
oStartFolder = "." '(the current folder of this script)
'// the item or token to work on:
sItem = "shader.exe" 'Name of file to find and name of file to copy (must be in same folder as this script, else we had to adjust this script)
'----------------------
'get files from oStartFolder:
If(1=0) Then
Set oFolder = oFSO.GetFolder(oStartFolder)
'Wscript.Echo oFolder.Path
Set colFiles = oFolder.Files
For Each oFile in colFiles
'Wscript.Echo oFile.Name
'Wscript.Echo oFile.Path
' oFile.Extension
' oFile.FileName
' oFile.FileSize
' oFile.FileType
' oFile.LastAccessed
' oFile.LastModified
funForEachFileDo oFile.Path
Next
End If
'----------------------
'get files from all sub folders:
strOUTvar = ""
ShowSubfolders oFSO.GetFolder(oStartFolder)
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
'Wscript.Echo Subfolder.Path
Set oFolder = oFSO.GetFolder(Subfolder.Path)
Set colFiles = oFolder.Files
For Each oFile in colFiles
funForEachFileDo oFile.Path
Next
'Wscript.Echo
ShowSubFolders Subfolder
Next
End Sub
'----------------------
Function funForEachFileDo(inputStr)
'debug:
'Wscript.Echo inputStr
'alternative a:
'strOUTvar = strOUTvar & inputStr & vbCRLF
'alternative b:
'If UCase(oFSO.GetExtensionName(oFile.name)) = "TXT" Then
'If oFSO.GetBaseName(oFile.name) = "BASENAME" Then
'If oFSO.GetFileName(oFile.name) = "FILENAME.ext" Then
If oFSO.GetFileName(inputStr) = sItem Then
'Wscript.Echo inputStr
'strOUTvar = strOUTvar & inputStr & vbCRLF
strGetParentFolderName = oFSO.GetParentFolderName(inputStr)
'Wscript.Echo inputStr & vbLF & strGetParentFolderName
'oFSO.CopyFile(Source, Dest [,Overwrite (True/False)]
oFSO.CopyFile sItem, strGetParentFolderName & "\" & sItem , true
End If
End Function ' funForEachFileDo()
'----------------------
'Output, write to file in current working dir:
If(1=0) Then
If(Len(strOUTvar) > 0) Then
Set NewFile = oFSO.CreateTextFile("___Logfile.txt", True)'True=overwrite
NewFile.WriteLine(strOUTvar)
NewFile.Close
End If
End If
'----------------------
Wscript.Echo "done"
'EOF
HTH?