Removing the DirectoryName from FileName

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Removing the DirectoryName from FileName

Postby sbisin » Tue Jun 27, 2023 9:20 am

Hello,

I have many hundreds of folders containing files that have filename containing at the beginning the name of the directory containing the files such as

- DirectoryName/DirectoryName - 01.jpg
- DirectoryName/DirectoryName - ABC.avi
- DirectoryName/DirectoryName - A1Z.mp4
..

how can I remove the initial part "DirectoryName" of the filename so that the files in the example are renamed in

- DirectoryName/01.jpg
- DirectoryName/ABC.avi
- DirectoryName/A1Z.mp4
..

NB: also the "Directory Name" contains always the " - " substring, just to make easier the task..

Thanks in advance
Steve
sbisin
 
Posts: 1
Joined: Tue Jun 27, 2023 9:10 am

Re: Removing the DirectoryName from FileName

Postby therube » Tue Jun 27, 2023 6:09 pm

1:RegEx, enable Simple
Code: Select all
Match:  %1-%2
Replace:  %2

%1 matches everything up to the (first) - [dash]
- matches [dash]
%2 matches everything else

Code: Select all
DirectoryName - 01.jpg
->    01.jpg
DirectoryName - ABC.avi
->    ABC.avi
DirectoryName - A1Z.mp4
->    A1Z.mp4
DirectoryName - A1Z - abcdefg - 123456789.mp4
->    A1Z - abcdefg - 123456789.mp4
therube
 
Posts: 1319
Joined: Mon Jan 18, 2016 6:23 pm


Return to Javascript Renaming