Finding the 1st file in the folders

English support forum

Moderators: white, Hacker, petermad, Stefan2

syd
Junior Member
Junior Member
Posts: 18
Joined: 2021-09-27, 14:44 UTC

Finding the 1st file in the folders

Post by *syd »

Hello all,
I have a problem.
I have a list of folders like:
folder01: 01.abc, 02.abc, 03.abc
folder02: 04.abc, 05.abc, 06.abc
I need to insert an extra number to the name of the file like that:
folder01: 01 D01.abc, 02 D02.abc, 03 D03.abc
folder02: 04 D01.abc, 05 D02.abc, 06 D03.abc
For doing that, my first idea is to locate every first file of each folder, then rename it to [N] D01, then to locate the 2nd file, rename it to [N] D02 etc. , but I can't find any option/plugin to be able to locate files by their indexes. Anybody has the solution?
Regards,
Syd
hi5
Power Member
Power Member
Posts: 551
Joined: 2012-11-03, 11:35 UTC
Contact:

Re: Finding the 1st file in the folders

Post by *hi5 »

Sort by name first so they are on the correct order (check sorting options in Preferences, Display, Sort Method if need be) and try with

[N] D[C:2]
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
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

Try this: https://madsenworld.dk/tcmd/multirenamecounter.png - remember so select all the files before you open the multi-rename tool.

If you really want to go to the first file in a folder you can use the command cm_GoToFirstFile.
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 »

Thanks for trying. I'm afraid that both methods makes the same, so the effect is:
\folder01\01.abc -> 01 D01.abc -ok
\folder01\02.abc -> 02 D02.abc -ok
\folder02\03.abc -> 03 D03.abc instead of 03 D01.abc
\folder02\04.abc -> 04 D04.abc instead of 04 D02.abc
(all the folders need to start from 'D01').
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
Hmm, in your first post you write that 03.abc is in folder01.

But anyway if you get:
\folder02\03.abc -> 03 D03.abc instead of 03 D01.abc
there must be some marked files before 03.abc in folder02

Look at my screenshot - it starts at 04.abc and renames it to 04 D01.abc (like you want).
Make sure that the start number is set to 1 in the "Define counter (C)" section.

Could you maybe send a screenshot of your folder02 ? - maybe there is something you havent informed us about...
Last edited by petermad on 2021-09-27, 21:19 UTC, edited 1 time in total.
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 »

I have like 1200 folders (for start), containing different amount of files and I need to add the number Dxx starting from D01 in each of them.
I don't have them marked. I can sort the folders for like 15 categories (same number of files), then start to rename it by D[C] and then rename it as they supposed to be, leaving [N] (D[C]), but it takes too long, and if there's an error, I'll be doomed forever. By the end, I will have to change like 400k of files by that so I'm looking for the best option, hopefully, using Total Commander.
The biggest folder may contain like 9 files, so I'm ok to start all over 9 times (if I find a way to catch the index file name, might be the answer). Supposed to be something like that.
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

Hmm, it sounds like you are renaming when in Branch view (Ctrl+B) - that would explain the wrong numbers in folder02 - TC doesn't now to retart the counting when the file is in a new folder .
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 »

Ctrl + M
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

Yes but before pressing Ctrl+M have you then envoked Branch view - to show the content of all subfolders in the same file panel - If you haven't done that I cannot understand why Folder02 should start counting from 03 in stead of 01, and I cannot understand how you can comtemplate renaming files in many folders in one go.
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 »

First I'm searching for 'abc' - I have a list of files (in my case 01, 02, 03 and 04 (let's keep to that I keep 2 files in folders), then Ctrl+M and there is only one file with D02. I don't understand what you are suggesting. Can you tell me step by step, please?
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 »

First I'm searching for 'abc'
And what do you do after the search - do you "Feed to listbox"?
Last edited by petermad on 2021-09-27, 21:49 UTC, edited 1 time in total.
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
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 is the problem - if you multi-rename files in Feed to listbox (or in Branch view) then the Multi-rename tool sees it as ONE folder and increases the counter by one for each of the files that where selected in the file panel when you press Ctrl+M - so the fourth selected file will always count as no 4 no matter which directory it belongs to.

I don't think there is a way to do it, without multi-renaming each folder at a time - and I can see that is tedious with 1200 folders.
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 »

I was pretty exciting to find the solution here.
I have an idea, today. Let's say all the folders are located in c:/test/
1. I empty the recycle bin
2. Listing all the files, from all the folders
3. Renaming (all) to '01'
-there will be a warning about double names - I proceed with creating '1st_file.abc' and then stop
->that way I have the first file named '1st_file' in each folder (I looses it's original name, but just for now)
4. I search for '1st_file.abc' and delete them to Recycle Bin
5. I rename the project folder from 'c:/test/' to 'c:/test01/'
6. I restore the files from Recycle Bin
7. I enter the multi-file-renaming-tool shortcut in Total Commander (Ctrl+M)
8. I select whatever and hit 'Undo'
->I have folders just with the first files, with original names
9. I search for all the *.abc files in c:/test/ folder
10. I rename it to '[N] 01'

Same steps with '2nd_file' etc. So it works, but I have to do that so many times as the number of files in folders, so in my case - that's 9.
If somebody find the better solution, that will help a lot. Also, maybe, there's a way to do that as from a script, instead of doing it manually.
I tried record actions, but with that many files, when I make a mistake, it's some kind of disaster.
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

I have made this batch script that should do the job:

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 exist "%%~pf* D0!c!%%~xf" (echo File already renamed) else ren "%%f" "%%~nf D0!c!%%~xf"
echo.
pause
If you save the code above as RenameD0X.bat in your TC program directory, then you can use this button to run the script - TC will automatically run it on the folders in the active panel:

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_PATH%\RenameD0X.bat

wcmicons.dll,63
Rename (add D0x) to all file names in all subfolders


-1
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
NOTE - the script assumes that you want to rename all files in the subfolders, if you only want to rename files of a certain type, the script has to be changed.

The script will only rename files that does not already has D0X in the filename, so there is no risk of double renaming if the script is accidently run twice.


You can also use this button without a RenameD0X.bat file:

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 not exist "%%~pf* D0!c!%%~xf" if "%%~xf"==".abc" ren "%%f" "%%~nf D0!c!%%~xf"D0!c!%%~xf"
wcmicons.dll,63
Rename (add D0x) to all file names in all subfolders

1
-1
Since there is no warnings with this button, it will only rename *.abc files and still only once.
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
Post Reply