remove folder name from file name

Bulk Rename Utility How-To's

remove folder name from file name

Postby lumpitor » Wed Jun 17, 2020 10:33 am

Hello,
how to remove folder name from file name.

I have a lot of folders which contain files, that contain in file name also folder name.
I would like to shorten file names.

example:
D:\music\metallica\
contains files with names:
Metallica - For Whom The Bell Tolls.mp3

Thanx :)
lumpitor
 
Posts: 1
Joined: Wed Jun 17, 2020 10:25 am

Re: remove folder name from file name

Postby RegexNinja » Fri Jun 19, 2020 1:15 am

For the 1-example, where filenames begin with FolderName, then a series of spaces/hyphens:

Javascript:
pfolder=(object('folder')).replace(/.*\\([^\\]+)\\$/g,'$1')
match=new RegExp('^'+pfolder+'[- _]*',"g")
newName=name.replace(match,'')

Results like:
Metallica - For Whom The Bell Tolls.mp3 ----> For Whom The Bell Tolls.mp3
RegexNinja
 
Posts: 134
Joined: Fri Feb 21, 2020 5:26 pm


Return to How-To


cron