select same size file on second side of TC

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Sysin
Junior Member
Junior Member
Posts: 6
Joined: 2019-06-05, 07:59 UTC

select same size file on second side of TC

Post by *Sysin »

Hello Alls,

I would like to ask You for advise.

What I need.

In left side of TC I select some files. And what I need is by some command find same file on second side and make a selection of them. BUT selection has to be made by size NOT by name.

What i found and it working perfectly for names is this command: cm_FocusLeft,cm_CopyNamesToClip,cm_FocusRight,cm_LoadSelectionFromClip
I need very similar command but it should look something like that:
cm_FocusLeft,cm_CopySizesToClip,cm_FocusRight,cm_LoadSelectionFromClip (of course this doesnt work - cm_CopySizesToClip - not exist)

Why I need it is not so important by if You interesting, it is because I lost all data from HDD.
I recovered everything what was possible and restore program create few folders named according to partitions(there are correct named subfolders) and one more folder called RAW files(subfolders named according file type).
And because all data(files) in partition folders are not possible to open(but their are in correct folders) I have to replace them from RAW folder. But how to match them? Only solution what I found is match them according their sizes. But of course I dont want to do it handly, because there is more then 50k files ....
May be somebody from You will have better solution ;-). I know it is bit confusing :-).

So all advice are welcome!!!

Thanks a lot
Sysin
Sysin
Junior Member
Junior Member
Posts: 6
Joined: 2019-06-05, 07:59 UTC

Re: select same size file on second side of TC

Post by *Sysin »

Hello,
it is not possible or my english is so bad that You dont understand what I want/mean?
please try help me with it.

Thanks a lot
Sysin
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: select same size file on second side of TC

Post by *Stefan2 »

2Sysin

Hi and welcome.

Just add the details of what you really want to do, together into a small block of information.
If you want to post your prose it's fine too, but it doesn't help to pick out the really important details (and why should I? You want something to know)

- - -

So you have files with the right content in one panel,
and files with same size and the correct name in other panel?

Now you want to do what?
- for each file X in one panel
- - - search the file Y with same size in other panel
- - - - - take there the file name of Y and rename X with that name?


Could be done, possible with a script,.... but... do that makes really any sense for you? (ok, could make sense in some circumstances)





 
Sysin
Junior Member
Junior Member
Posts: 6
Joined: 2019-06-05, 07:59 UTC

Re: select same size file on second side of TC

Post by *Sysin »

I want to do:
-for each selected file(correct name,date,time) in one panel(Panel A)
--search the file Y with same size(wrong name,date,time) in second panel(Panel B)
---select files in second panel(Panel B)

OR better:
-for each selected file(correct name,date,time) in one panel(Panel A)
--search the file Y with same size(wrong name,date,time) in second panel(Panel B)
---copy searched file from Panel B to Panel A
----replace original file with using name,date,time from Panel A

and it really make sense for me. I tried do it manually. But after 1 hour I was really tired from it. I did it cca 100 times. But I need do this for 50 thousands files ...

So if somebody help or give me some hint how to do it I will be very grateful.

Thanks again!
Sysin
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: select same size file on second side of TC

Post by *Stefan2 »

EDIT: Ignore this post as I understood it wrong as you can read on the next posts...

Bitte gehen Sie weiter, hier gibt es nichts zu sehen!





OK, example script with message boxes only for an first test:

My test files:

SOURCE ACTIVE folder

Code: Select all

10.txt	10	18.02.2019 12:34	-a--
11.txt	11	18.02.2019 12:34	-a--
164.txt	164	19.02.2019 13:38	-a--
18580.docx	18.580	18.02.2019 12:45	-a--
TARGET folder

Code: Select all

ElEVEN.ext		11	18.05.2019 11:11	-a--
Hundred.ext		164	19.05.2019 10:30	-a--
TEN.ext		            10	18.05.2019 10:10	-a--
TenTousand.ext		18.580	18.05.2019 10:40	-a--
TEST.xml		164	19.02.2019 13:38	-a--
__INFOs.txt		0	07.06.2019 12:03	-a--



START SCRIPT by button click



Results (here messages only, in real there would be a rename command):

Code: Select all


---------------------------
Total Commander VBScript
---------------------------
Active:
X:\Source folder\

Target:
X:\Target\


Continue ?
---------------------------
Ja YES  //  Nein   No
---------------------------


# # #

---------------------------

---------------------------
Rename 10.txt
 with TEN.ext ; 07.06.2019 11:59:41 ; 07.06.2019 12:00:32 ; 18.05.2019 10:10:10 ?
---------------------------
OK   
---------------------------

# # #

---------------------------

---------------------------
Rename 11.txt
 with ELEVEN.ext ; 07.06.2019 11:59:41 ; 07.06.2019 12:00:42 ; 18.05.2019 11:11:11 ?
---------------------------
OK   
---------------------------

# # #

---------------------------

---------------------------
Rename 164.txt
 with Hundred.ext ; 07.06.2019 12:00:00 ; 07.06.2019 12:00:52 ; 19.05.2019 10:30:50 ?
---------------------------
OK   
---------------------------

# # #

---------------------------

---------------------------
Rename 164.txt
 with TEST.xml ; 07.06.2019 11:42:18 ; 07.06.2019 11:49:21 ; 19.02.2019 14:38:55 ?	<<< PROBLEM two files with same size !!
---------------------------
OK   
---------------------------

# # #

---------------------------

---------------------------
Rename 18580.docx
 with TenTousand.ext ; 07.06.2019 11:59:41 ; 07.06.2019 12:01:07 ; 18.05.2019 10:40:30 ?
---------------------------
OK   
---------------------------



Possible Problem:
Rename 164.txt with Hundred.ext ; 07.06.2019 12:00:00 ; 07.06.2019 12:00:52 ; 19.05.2019 10:30:50 ?
Rename 164.txt (is now Hundred.ext and not found anymore for renaming)
with TEST.xml ; 07.06.2019 11:42:18 ; 07.06.2019 11:49:21 ; 19.02.2019 14:38:55 ? <<< PROBLEM two files with same size !!



The Script:

Code: Select all

'       VBS-Script to use with TotalCommander.
'       _ForEachSelFileDo - x.vbs

'       Found at: https://ghisler.ch/board/viewtopic.php?p=356025#p356025

'       Purpose: For each file in Source, search for file with same size in target,
'                next rename in Source with name of file in target and transfer file properties.

'       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:   "%P" "%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 '%P' '%T'",,"VBScript - ERROR"
    WScript.Quit
Else
    sTC_A = Wscript.arguments.Item(0) ' The TC Active panel due to the "%P" parameter
    sTC_T = Wscript.arguments.Item(1) ' The Target panel due to the "%T" parameter
End If 



MB = MsgBox("Active:"&vbLF&sTC_A &vbLF&vbLF& "Target:"&vbLF&sTC_T _
		&vbLF&vbLF&vbLF&"Continue ?", VBYesNo+vbQuestion,"Total Commander VBScript")
If (MB = vbNo) Then WScript.Quit 



SET FSO	       = CreateObject("Scripting.FileSystemObject")
Set oFolder_A  = FSO.GetFolder(sTC_A)
Set colFiles_A = oFolder_A.Files
Set oFolder_T  = FSO.GetFolder(sTC_T)
Set colFiles_T = oFolder_T.Files

For Each oFileA in colFiles_A
sNameA = oFileA.Name
sSizeA = oFileA.Size
iCount = iCount +1
	For Each oFileT in colFiles_T
		sSizeT = oFileT.Size
		If (sSizeT = sSizeA) Then
			sNameT = oFileT.Name
			CD = oFileT.DateCreated
			AD = oFileT.DateLastAccessed
			MD = oFileT.DateLastModified
			msgbox "Rename " & sNameA &vbLF _
					&" with " & sNameT   &" ; "& CD &" ; "&AD&" ; "&MD &  " ?"
		End If
	Next
	If(iCount = 5) Then Exit For
Next





 
Sysin
Junior Member
Junior Member
Posts: 6
Joined: 2019-06-05, 07:59 UTC

Re: select same size file on second side of TC

Post by *Sysin »

Hello Stefan,
thanks a lot for this!

Anyway there is few mistakes.

1, it should work only with selected files
2, correct name,date,time is from first panel not from second.(But its detail which I hope will be able to "rewrite" from Your sorce file)

So now I would like to ask You for put there commands for renaming, redating, retiming and copying selected files instead of msgbox.

Thanks a lot !!!!!!
Sysin
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: select same size file on second side of TC

Post by *Stefan2 »

>>>mistakes

> 1: ok, no problem
> 2: so I understood it wrong. You want:
Source: Name + Timestamp + Size
Target: the content from the file with same Size
Basically just exchange content from first panel (active Source) with file content from second panel (inactive Target) which have the same size.


---------------------------
---------------------------
Found a buddy !

Source: 10.txt
Buddy : TEN.ext

Copy TEN.ext to Source folder,
next rename TEN.ext to 10.txt
and copy also the timestamp ?
---------------------------
OK
---------------------------



Try this (still unarmed) script


' CMD: "%COMMANDER_PATH%\TOOLs\VBS\ForEachSelFileDo.vbs"
' PARAM: "%F" "%T"

Code: Select all

'       VBS-Script to use with TotalCommander.
'       _ForEachSelFileDo - x.vbs
'       Found at: https://ghisler.ch/board/viewtopic.php?p=356025#p356025
'       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 

SET FSO	= CreateObject("Scripting.FileSystemObject")
Set oFolder_T  = FSO.GetFolder(sTC_T)
Set colFiles_T = oFolder_T.Files

If  FSO.FileExists(sTCtempList) Then
	
	Set oTextStream = FSO.OpenTextFile(sTCtempList,1)
	Do Until oTextStream.AtEndOfStream
		iCurrFileCount = iCurrFileCount + 1
		
		sFullName = oTextStream.ReadLine
		If(Right(sFullName,1)= "\") Then 
		Else
			Set oFileA = FSO.GetFile(sFullName)
			sNameA = oFileA.Name
			sSizeA = oFileA.Size
			CD = oFileA.DateCreated
			AD = oFileA.DateLastAccessed
			MD = oFileA.DateLastModified

			For Each oFileT in colFiles_T
				sSizeT = oFileT.Size
				If (sSizeT = sSizeA) Then
					sNameT = oFileT.Name

					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 ?"&vbLF 
				End If 'same size
			Next
		If(iCurrFileCount = 5) Then Exit Do
		End If 'file or folder
	Loop 'do
	oTextStream.Close
	'MsgBox "Done " 
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




I hope I get it now right...





EDIT:

Here is the "armed" script.

It is not that easy to change a file timestamp with VBS, or I didn't find the right answer. Anyway here is a (for me) working script:
Spoiler

Code: Select all

'       VBS-Script to use with TotalCommander.
'       _ForEachSelFileDo - x.vbs
'       Found at: https://ghisler.ch/board/viewtopic.php?p=356025#p356025
'		Version 2  , 2019-06-07 Fri 17:29: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 

SET FSO	= CreateObject("Scripting.FileSystemObject")
Set oFolder_T  = FSO.GetFolder(sTC_T)
Set colFiles_T = oFolder_T.Files

If  FSO.FileExists(sTCtempList) Then
	
	Set oTextStream = FSO.OpenTextFile(sTCtempList,1)
	Do Until oTextStream.AtEndOfStream
		iCurrFileCount = iCurrFileCount + 1
		
		sFullName = oTextStream.ReadLine
		If(Right(sFullName,1)= "\") Then 
		Else
			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

					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 ?"&vbLF , VBYesNo+vbQuestion,"Total Commander VBScript")
					If (MB = vbYes) 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
				End If 'same size
			Next
		If(iCurrFileCount = 5) Then Exit Do
		End If 'file or folder
	Loop 'do
	oTextStream.Close
	'MsgBox "Done " 
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



 
Sysin
Junior Member
Junior Member
Posts: 6
Joined: 2019-06-05, 07:59 UTC

Re: select same size file on second side of TC

Post by *Sysin »

Stefan !!!,

You are GOD!

It has to be somehow rewarded! So Next few beers has to be on me!

So last information what I need is Your paypal account.

Thanks a lot
Sysin
Sysin
Junior Member
Junior Member
Posts: 6
Joined: 2019-06-05, 07:59 UTC

Re: select same size file on second side of TC

Post by *Sysin »

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?

Also put there Yes to all

and finally if it can search also subfolders.

Thanks a lot
Sysin

P.S. Still own You some beers so give me Your paypal acc.(mail, to PM)
User avatar
Stefan2
Power Member
Power Member
Posts: 4132
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: select same size file on second side of TC

Post by *Stefan2 »

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 :D Just do you help two others too and that's all, ok? :wink:



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


 
Post Reply