Renaming based on folder struccture from top level folder

A swapping-ground for Regular Expression syntax

Renaming based on folder struccture from top level folder

Postby jukul » Thu Jan 02, 2020 7:58 am

I have been pulling some files and I just realized that I have incorrectly used a title expression to name these files. Now, I have hundreds of files in different sub folders that need to be renamed:

An example of these files looks like below:

../Media/eLearning$ ls -alR | head -n 1000
.:
total 4909
drwxrwxrwx 102 user media 106 Jan 1 21:35 .
drwxrwxr-x 9 user media 10 Dec 31 18:16 ..
drwxrwxrwx 2 user media 6 Dec 30 11:52 LinkedIn Learning - Amazon Web Services - Enterprise Security
drwxrwxrwx 2 user media 35 Jan 1 12:00 LinkedIn Learning - Applied Machine Learning - Algorithms
drwxrwxrwx 2 user media 38 Jan 1 13:46 LinkedIn Learning - Applied Machine Learning - Foundations

./LinkedIn Learning - Amazon Web Services - Enterprise Security:
total 41994
drwxrwxrwx 2 user media 6 Dec 30 11:52 .
drwxrwxrwx 102 user media 106 Jan 1 21:35 ..
-rw-rw-rw- 1 user media 21390920 Jan 4 2017 01-Welcome.mp4
-rw-rw-rw- 1 user media 1890708 Jan 4 2017 02-What you should know.mp4
-rw-rw-rw- 1 user media 6014074 Jan 4 2017 04-The AWS security landscape.mp4
-rw-rw-rw- 1 user media 13819116 Jan 4 2017 09-Configure IAM policies.mp4

./LinkedIn Learning - Applied Machine Learning - Algorithms:
total 337167
drwxrwxrwx 2 user media 35 Jan 1 12:00 .
drwxrwxrwx 102 user media 106 Jan 1 21:35 ..
-rw-rw-rw- 1 user media 42358614 May 10 2019 01-The power of algorithms in machine learning.mp4
-rw-rw-rw- 1 user media 2105003 May 10 2019 02-What you should know.mp4
-rw-rw-rw- 1 user media 1954820 May 10 2019 03-What tools you need.mp4
-rw-rw-rw- 1 user media 3323990 May 10 2019 04-Using the exercise files.mp4
-rw-rw-rw- 1 user media 4259330 May 10 2019 05-Defining model vs. algorithm.mp4
-rw-rw-rw- 1 user media 5627394 May 10 2019 06-Process overview.mp4
-rw-rw-rw- 1 user media 20094439 May 10 2019 07-Clean continuous variables.mp4
-rw-rw-rw- 1 user media 17071872 May 10 2019 08-Clean categorical variables.mp4
-rw-rw-rw- 1 user media 10697900 May 10 2019 09-Split into train, validation, and test set.mp4


./LinkedIn Learning - Applied Machine Learning - Foundations:
total 370130
drwxrwxrwx 2 user media 38 Jan 1 13:46 .
drwxrwxrwx 102 user media 106 Jan 1 21:35 ..
-rw-rw-rw- 1 user media 38026414 May 3 2019 01-Leveraging machine learning.mp4
-rw-rw-rw- 1 user media 1642839 May 3 2019 02-What you should know.mp4
-rw-rw-rw- 1 user media 1700524 May 3 2019 03-What tools you need.mp4
-rw-rw-rw- 1 user media 3204096 May 3 2019 04-Using the exercise files.mp4
-rw-rw-rw- 1 user media 6272344 May 3 2019 05-What is machine learning.mp4
-rw-rw-rw- 1 user media 8710829 May 3 2019 06-What kind of problems can this help you solve.mp4
-rw-rw-rw- 1 user media 12727640 May 3 2019 07-Why Python.mp4
-rw-rw-rw- 1 user media 7205383 May 3 2019 08-Machine learning vs. Deep learning vs. Artificial intelligence.mp4
-rw-rw-rw- 1 user media 11064663 May 3 2019 09-Demos of machine learning in real life.mp4
-rw-rw-rw- 1 user media 9418411 May 3 2019 10-Common challenges.mp4



My intention is to rename the files from something like:

Original:
10-Common challenges

New:
Applied Machine Learning - Foundations - S01E10 - Common challenges.mp4

The problem is I need to do this recursively against all folders from the eLearning and below.

Is there a way to achieve this via Regular Expression, I have been trying to figure out a pattern for a while but have not had much luck. Mainly because I need to pull the name from the above folder dynamically, and I just haven't figured out how to do this in Bulk Rename Utility.
jukul
 
Posts: 2
Joined: Thu Jan 02, 2020 7:26 am

Re: Renaming based on folder struccture from top level folder

Postby jukul » Thu Jan 02, 2020 8:16 am

I don't see an ability to edit my previous post, but I just realized that I have some things in the eLearning folder that would break the recurisve ability for this:

udemy - Python and Django Full Stack Web Development:
total 1183
drwxrwxrwx 29 user media 29 Dec 29 14:42 .
drwxrwxrwx 102 user media 106 Jan 1 21:35 ..
drwxrwxrwx 2 user media 46 Dec 29 11:17 01 Course Introduction
drwxrwxrwx 2 user media 15 Dec 29 11:18 02 Front-End Introduction
drwxrwxrwx 2 user media 99 Dec 29 11:20 03 HTML Level One - Basics
drwxrwxrwx 2 user media 111 Dec 29 11:24 04 HTML Level Two - Advanced

../Media/eLearning$ ls -al udemy\ -\ Python\ and\ Django\ Full\ Stack\ Web\ Development/01\ Course\ Introduction/
total 68549
drwxrwxrwx 2 user media 46 Dec 29 11:17 .
drwxrwxrwx 29 user media 29 Dec 29 14:42 ..
-rw-rw-rw- 1 user media 3514 Dec 29 11:17 '001 Introduction.de.srt'
-rw-rw-rw- 1 user media 3262 Dec 29 11:17 '001 Introduction.en.srt'
-rw-rw-rw- 1 user media 3615 Dec 29 11:17 '001 Introduction.es.srt'
-rw-rw-rw- 1 user media 3567 Dec 29 11:17 '001 Introduction.fr.srt'
-rw-rw-rw- 1 user media 3477 Dec 29 11:17 '001 Introduction.id.srt'
-rw-rw-rw- 1 user media 3456 Dec 29 11:17 '001 Introduction.it.srt'
-rw-rw-rw- 1 user media 4044 Dec 29 11:17 '001 Introduction.ja.srt'
-rw-rw-rw- 1 user media 8375859 Dec 29 11:17 '001 Introduction.mp4'
-rw-rw-rw- 1 user media 3548 Dec 29 11:17 '001 Introduction.pl.srt'
-rw-rw-rw- 1 user media 3594 Dec 29 11:17 '001 Introduction.pt.srt'
-rw-rw-rw- 1 user media 3735 Dec 29 11:17 '001 Introduction.ro.srt'
-rw-rw-rw- 1 user media 3436 Dec 29 11:17 '001 Introduction.tr.srt'
-rw-rw-rw- 1 user media 15239 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.de.srt'
-rw-rw-rw- 1 user media 13724 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.en.srt'
-rw-rw-rw- 1 user media 14881 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.es.srt'
-rw-rw-rw- 1 user media 15480 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.fr.srt'
-rw-rw-rw- 1 user media 14818 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.id.srt'
-rw-rw-rw- 1 user media 14406 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.it.srt'
-rw-rw-rw- 1 user media 17041 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.ja.srt'
-rw-rw-rw- 1 user media 14803923 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.mp4'
-rw-rw-rw- 1 user media 14394 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.pl.srt'
-rw-rw-rw- 1 user media 14890 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.pt.srt'
-rw-rw-rw- 1 user media 15252 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.ro.srt'
-rw-rw-rw- 1 user media 14558 Dec 29 11:17 '002 Course Overview Dont Skip this Lecture.tr.srt'



This would prevent the pattern as there is a different naming scheme being applied here with these files.
jukul
 
Posts: 2
Joined: Thu Jan 02, 2020 7:26 am

Re: Renaming based on folder struccture from top level folder

Postby therube » Fri Jan 03, 2020 7:18 pm

As a start, you can set a filter (12:) to only affect .mp4, so your .srt would be left as is.
(Though I would think ? the .srt would need to be named relative to the .mp4, wouldn't they?)

LinkedIn Learning - Applied Machine Learning - Foundations, the parent directory, you can pick up from:

9:Append Folder Name
Name: Prefix

You'd have to go back after the fact & remove the 'LinkedIn Learning -' part.
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Renaming based on folder struccture from top level folder

Postby RegexNinja » Sun Apr 05, 2020 4:58 am

Hi.
Unfortunately, BRU cant handle this in 1-run, since #1Regex must process before #9AppendFolderName
But like therube says, you could always split it up into different runs.

BRC doesnt have that limitation.. I see you're using ls/head.. If you also have sed avail..
Here's a batch with BRC64 to do what I believe you're looking for:

@echo off
For /f "delims=" %%A IN ('dir/b/s/ad') DO (
For /f "delims=" %%B IN ('dir/b "%%A"^|sed -r "1s/^(01)-.*/\1/;q"') DO (
For /f "delims=" %%C IN ('dir/b "%%A"^|sed -n -r "2{s/^(02)-.*/\1/p;q}"') DO (
If "%%B"=="01" If "%%C"=="02" (
brc64 /Dir:"%%A" /AppendFolder:"P:|:1:" /Regexp:".*? - (.+)[|](0[12])-(.+)$:\1 - S01E\2 - \3" /Regexp:".*[|](.*):\1"
))))
pause

Note the batch requires both sed/brc64 to be avail somewhere within %path%
Everything after the 1st Space-Space in ParentFolder is used as the prefix:
It also ensures that the 1st-2 files in each ParentFolder begin as 01- and 02- (respectively).

Batch Notes: %%A=ParentFolderName, %%B=01 (if 1st-name begins as 01-), %%C=02 (if 2nd-name begins as 02-)
Add /Execute to the end of the brc64 line to perform renames (as-is, it merely provides a preview of NewNames).
Run batch from any upper-level folder to affect all SubFolders that match per below:

ParentFolder: LinkedIn Learning - Applied Machine Learning - Foundations
01-AnyName ----------> Applied Machine Learning - Foundations - S01E01 - AnyName
02-AnyName ----------> Applied Machine Learning - Foundations - S01E02 - AnyName
TitleA-AnyName ------> no effect (doesnt begin with ##-)

ParentFolder: LinkedIn Learning - Applied Machine Learning - Foundations
01-AnyName ----------> no effect (next name doesnt begin as 02-)
01-AnyName ----------> no effect

ParentFolder: LinkedIn Learning-Applied Machine Learning-Foundations
01-AnyName ----------> no effect (no Space-Space in ParentFolder)
02-AnyName ----------> no effect (no Space-Space in ParentFolder)
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm


Return to Regular Expressions


cron