Click.
As for the button, for several selected files, you will need to replace "%Q%N" with "%S".
In the condition, it's possible to set a comparison of versions where they are, and where they are not, compare by date and size.
Moderators: white, Hacker, petermad, Stefan2
Click.
As for the button, for several selected files, you will need to replace "%Q%N" with "%S".
In the condition, it's possible to set a comparison of versions where they are, and where they are not, compare by date and size.
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...
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
Because you are trying to do this from a list with search results where there is no common parent folder, and the working directory in this case is %COMMANDER_PATH%. In addition, the file modification date is older than the one on the left.jesped wrote: ↑2023-11-22, 14:51 UTC Tried now in another SSD disk with games (S:) and it doesn't replace all the files:
Image: https://i.postimg.cc/JzCWMftz/image.png
If you didn't change anything in the button, then this couldn't happen.jesped wrote: ↑2023-11-22, 14:51 UTC Also, it creates a %~fd folder...
Image: https://i.postimg.cc/z3m4Dhzc/image.png
No, no. The search results on the left are just to show you that some files weren't updated, and those files have an older modified date.
This is how it looks now:Fla$her wrote: ↑2023-11-22, 19:46 UTCIf you didn't change anything in the button, then this couldn't happen.jesped wrote: ↑2023-11-22, 14:51 UTC Also, it creates a %~fd folder...
Image: https://i.postimg.cc/z3m4Dhzc/image.png
Thanks for the help, man. But Fla$her solution is more handy for my needs. Having a button that works with a live selection and a target folder is all I can ask for.
Can you show the text from update.log?
Try this:
Code: Select all
TOTALCMD#BAR#DATA
%ComSpec% /q/v/c for /r
"%T" %%d in (.) do set "d=%%d"&robocopy . "!d:~,-2!" "%S" /ndl /nfl /njh /njs /xo /xl
wcmicon2.dll,63
Replace the files in the folder structure of the passive|panel with the ones selected in the active panel
1
It is really weird, because it *does* work for the files inside the green area... but it doesn't for the ones in the red area, even when they clearly have an earlier Modified date.
You need to delete files past the Recycle Bin. To the Recycle Bin is not a deletion, but a move in essence.
There is only "lonely", i.e. folders do not contain files of the same name.jesped wrote: ↑2023-11-23, 01:38 UTC Previous button log is this one: https://drive.google.com/file/d/11l7Q_IKANpkgZDsTu-LHVumruCkDlPrp/view?usp=sharing
We are facing this here in the task of deleting empty folders. You need to find out what attributes such folders had before using the button.
Mmm... but when they can be deleted to the recyble bin that means they are not locked or in use by other app. When I get that with other files they can't be deleted, moved or renamed. I have to restart TC, Explorer or even Log Off/Restart Windows.
So it seems it didn't found them then, but the folders with the files inside are there.
The folders had no specific attributes and nothing weird. Only thing I can think of is that I customized their icons...
This is a downside of using rococopy, and there's no workaround.
Code: Select all
@echo off
Setlocal EnableDelayedExpansion
for /f %%i in ('dir /b/a/s "." ^| find /i "desktop.ini"') do (set d=%%~dpi
attrib !d:~,-1! +r
attrib !d:~,-1!)
Code: Select all
[em_test_tc_update_existing_files_command]
cmd=Powershell -ExecutionPolicy Bypass;
param=Get-Content """%UL"""|ForEach-Object -process {foreach ($file in (gci """%T""" -recurse)) {if ($file.name -eq (Split-Path $PSitem -leaf)) {Copy-Item $PSitem $file.fullname}}}
Code: Select all
# PowerShell : update existing target files if any : test environment
# target files: within system %TEMP% folder
'make test environment...'
$probe = "$env:Temp\probe"
$files = @("$probe\test\SIZE.txt","$probe\test\text.en.txt","$probe\test\text.readme.txt")
New-Item $files -force -Type file -value 'file' > $null
# source files: wherever the script runs
$files = @("SIZE.txt","text.en.txt","text.readme.txt")
New-Item $files -force -Type file -value 'updated' > $null