File renaming based on folder + adding zero before numbers

A swapping-ground for Regular Expression syntax

Re: File renaming based on folder + adding zero before numbers

Postby Jack2 » Sun Nov 18, 2018 12:56 pm

There might be more elegant ways, but you could make a text file of your filenames, use Excel to manipulate them into your desired filenames, and create a Data-Pairs list that you could use with BRU to rename them.

To do this:

Get a list of your filenames in a .TXT file using
windows command line (dir *.jpg /b /s /a:-D >Filelist.txt) (or similar, you might need to tweak the arguments);

or apps like
https://www.karenware.com/powertools/karens-directory-printer
.
or
.
https://download.cnet.com/PrintFolders/3000-2248_4-10067127.html

.

Starting with your list of paths/filenames:
2017/1/1.jpg
2017/1/2.jpg
2017/1/3.jpg
2017/1/4.jpg

.


Paste these into excel column A and also column B.

.


Highlight Column B and use menus option Data>Text to columns>Delimited>Delimiters:Other>/ >Finish
(I have excel 2013 - some of the navigation details may have changed since then)

this will give you:
column B - 2017
column C - 1 (your "S")
column D - 1.jpg, 2.jpg, 3.jpg, etc

.

paste this into Cell E1:
=C1&(IF((LEN(LEFT(D1,FIND(".",D1)-1)))=1,("00"&(LEFT(D1,FIND(".",D1)-1))),IF((LEN(LEFT(D1,FIND(".",D1)-1)))=2,("0"&(LEFT(D1,FIND(".",D1)-1))),(LEFT(D1,FIND(".",D1)-1)))))&".jpg"

.

paste this into Cell F1:
=A1&"|"&E1

.

Fill/Paste E1 and F1 down to the end of your data.
(Column E is your new filenames in your described format, Column F is a set of Rename Pairs, which you can use with BRU to rename the files)

.

copy-paste Column F into a new text document and save it somewhere as, say, NewPairs.txt .

.

go to BRU, use menu option Actions>Import Data Pairs, navigate to NewPairs.txt and load it.

in BRU main UI window, navigate to the folder with your original files and Select all the files in the main window in BRU, and rename them in the usual way.


.

(the formula in E1 splits-off the file extension from "1.jpg", then measures the length of the remaining name. If the length is 1 it prepends "00"; and if the length is 2 it prepends "0", giving you the 3-digit number format 001, 011, 111)
Jack2
 
Posts: 30
Joined: Wed Nov 14, 2018 4:32 pm

Return to Regular Expressions