Finding the 1st file in the folders

English support forum

Moderators: white, Hacker, petermad, Stefan2

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

Re: Finding the 1st file in the folders

Post by *Stefan2 »

syd wrote: 2021-10-29, 14:21 UTC What do you mean about 'Num+ button ?

The button to insert a "+" , but at the part of the keyboard which is for digits only:
7 8 9 -
4 5 6 +      << that
1 2 3 Enter


Or on a Notebook the number keys accessible together with the [FN] -key (but don't know if that works there)







 
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Finding the 1st file in the folders

Post by *petermad »

What do you mean about 'Num+
Yes the + key on the numeric keypad (just the one key). Note it only works after a search for "Find duplicate files" -> "Feed to listbox".

If you don't have a numeric keyboard you can use the menu: "Mark" -> "Select Group", or use the internal command cm_spreadselection

is there a simple way to change the script to makes files, even there are more of them then 9? Like D01..D10, not D01..D010?
I shall see what I can do
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Finding the 1st file in the folders

Post by *petermad »

This script should remove the leading 0 in D0x for values over 9:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do if not exist "%%~dpf*!D0!!c!*%%~xf" (if "%%H"=="" (ren "%%f" "%%G !D0!!c!%%~xf") else ren "%%f" "%%G !D0!!c! %%H%%~xf")
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1


Since this script can make enormous damage if run ín the wrong folder I suggest to let it ask before executing, so that it takes both a click on the button AND a press on OK to execute it:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
?(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do if not exist "%%~dpf*!D0!!c!*%%~xf" (if "%%H"=="" (ren "%%f" "%%G !D0!!c!%%~xf") else ren "%%f" "%%G !D0!!c! %%H%%~xf")
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
syd
Junior Member
Junior Member
Posts: 18
Joined: 2021-09-27, 14:44 UTC

Re: Finding the 1st file in the folders

Post by *syd »

petermad wrote: 2021-10-29, 20:47 UTC This script should remove the leading 0 in D0x for values over 9:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do if not exist "%%~dpf*!D0!!c!*%%~xf" (if "%%H"=="" (ren "%%f" "%%G !D0!!c!%%~xf") else ren "%%f" "%%G !D0!!c! %%H%%~xf")
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1
You're a magician! That works great. Do you have any idea why does it take so long, though. It takes 40mins to rename 21k files (the same, while using the button and by Total Commander's script). During renaming it does use like 2MB/s on my m.2 drive + just a very little power from CPU.
That 40mins it's super fantastic, for me, but my ambition requires to find a way to make it quicker.
We used to improve our work at the office by creating RAID0 with the fastest NVME drives available at the time.
Stefan2 wrote: 2021-10-29, 14:49 UTC
syd wrote: 2021-10-29, 14:21 UTC What do you mean about 'Num+ button ?

The button to insert a "+" , but at the part of the keyboard which is for digits only:
7 8 9 -
4 5 6 + << that
1 2 3 Enter


Or on a Notebook the number keys accessible together with the [FN] -key (but don't know if that works there)
Thanks, I use "+" all the time, but, still, I don't see how to delete the duplicats with saving the orginals.
Let's say I have 2 files:
c:\folder1\1.txt
c:\folder1\subfolder1\2.txt
and both contain the same content. I'm using "Find Files" -> advanced -> Find duplicate files -> "same size" + "same contents" -> Start search
so I end with the list of files (I click "Feed to list"):
1.txt
2.txt
--------------------------------------------------

I have to manually click one of them with a mouse. Or I can use Insert key, then arrow down, but when I have 1000 files like that it's annoying.
Do you have any idea how to avoid clicking?
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Finding the 1st file in the folders

Post by *petermad »

Let's say I have 2 files:
c:\folder1\1.txt
c:\folder1\subfolder1\2.txt
and both contain the same content. I'm using "Find Files" -> advanced -> Find duplicate files -> "same size" + "same contents" -> Start search
so I end with the list of files (I click "Feed to list"):
1.txt
2.txt
And after doing that it is that you have to press the Num+ button - try it.
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Finding the 1st file in the folders

Post by *petermad »

That 40mins it's super fantastic, for me, but my ambition requires to find a way to make it quicker.
If you are sure that there is ALWAY a space in the file names, and you don't need the safety of not renaming the files twice (by accidently pressing the button again and getting file names like: something D01 DO1 01.abc) then the script can be reduced to:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
?(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do ren "%%f" "%%G !D0!!c! %%H%%~xf")
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1

Try and see if this is faster...
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
syd
Junior Member
Junior Member
Posts: 18
Joined: 2021-09-27, 14:44 UTC

Re: Finding the 1st file in the folders

Post by *syd »

petermad wrote: 2021-11-02, 19:30 UTC
Let's say I have 2 files:
c:\folder1\1.txt
c:\folder1\subfolder1\2.txt
and both contain the same content. I'm using "Find Files" -> advanced -> Find duplicate files -> "same size" + "same contents" -> Start search
so I end with the list of files (I click "Feed to list"):
1.txt
2.txt
And after doing that it is that you have to press the Num+ button - try it.
yey! :-)

petermad wrote: 2021-11-02, 19:37 UTC
That 40mins it's super fantastic, for me, but my ambition requires to find a way to make it quicker.
If you are sure that there is ALWAY a space in the file names, and you don't need the safety of not renaming the files twice (by accidently pressing the button again and getting file names like: something D01 DO1 01.abc) then the script can be reduced to:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
?(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do ren "%%f" "%%G !D0!!c! %%H%%~xf")
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1

Try and see if this is faster...
25min! Thanks, it's fantastic.
syd
Junior Member
Junior Member
Posts: 18
Joined: 2021-09-27, 14:44 UTC

Re: Finding the 1st file in the folders

Post by *syd »

petermad wrote: 2021-11-02, 19:37 UTC
That 40mins it's super fantastic, for me, but my ambition requires to find a way to make it quicker.
If you are sure that there is ALWAY a space in the file names, and you don't need the safety of not renaming the files twice (by accidently pressing the button again and getting file names like: something D01 DO1 01.abc) then the script can be reduced to:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
?(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do ren "%%f" "%%G !D0!!c! %%H%%~xf")
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1
Works amazing, but creates an extra ")" in the extension (like "test d01.abc)". I thought it's because of the part "else (set D0=D0))", but after reducing .abc) goes to .abc, but there are no more D10, just D09, then there's nothing. Not a big deal, one change in Total Commander but the code is 99% complete.
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Finding the 1st file in the folders

Post by *petermad »

2syd
but creates an extra ")" in the extension (like "test d01.abc)".
It was due to a remaining ) at the end of the script. This button should work:

Code: Select all

TOTALCMD#BAR#DATA
%COMSPEC% /V:ON /C
?(set c=0) & (set d=0) & for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do ren "%%f" "%%G !D0!!c! %%H%%~xf"
wcmicons.dll,63
Add D0x after the first space in all file names in all subfolders

1
-1
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
syd
Junior Member
Junior Member
Posts: 18
Joined: 2021-09-27, 14:44 UTC

Re: Finding the 1st file in the folders

Post by *syd »

petermad wrote: 2021-11-16, 12:40 UTC 2syd
but creates an extra ")" in the extension (like "test d01.abc)".
It was due to a remaining ) at the end of the script. This button should work:

2petermad

Ok, the button works, but if I make the .bat file, there's still an extra ")" at the end. I'm to nervous to keep the buttons, I have Total Commander opened on all PCs all the time and I have children/emloyees/cats/dogs/hedgehogs all around all the time.

Code: Select all

@echo off
echo Are you sure you want to rename all files in this folder and it's subfolders?
echo.
echo If not press Ctrl+C to cancel
echo.
pause

SETLOCAL ENABLEDELAYEDEXPANSION

set c=0
set d=0

echo Renaming files...
echo.

for /r %%f in (*) do (if not "%%~pf"=="!d!" set c=0) & (set d=%%~pf) & (set /a c+=1) & (if !c! GTR 9 (set D0=D) else (set D0=D0)) & for /f "tokens=1* delims= " %%G in ("%%~nf") do ren "%%f" "%%G !D0!!c! %%H%%~xf")
echo.
pause
User avatar
petermad
Power Member
Power Member
Posts: 14739
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Finding the 1st file in the folders

Post by *petermad »

2syd

Just remove the ) at the end of the line in the .bat file...
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
syd
Junior Member
Junior Member
Posts: 18
Joined: 2021-09-27, 14:44 UTC

Re: Finding the 1st file in the folders

Post by *syd »

Yes, it works perfectly!
Post Reply