#11 2019-03-04 11:19

HexaPro
Member
Registered: 2019-03-03
Posts: 15

Re: Rename file exactly like another file with a different extension

Sorry, I just realize that I cannot copy the folder name as the .mp4 name. Since the .mp4 name has the info of the video type, like 'x264 or H264' while the folder isn't. Because some of my .mp4 has no .srt yet, and that info 'x264 or H264' is important for me to search the correct .srt file for the video. So I really need to copy just the .mp4 file name as the .srt file name, or perhaps even rename the folder as the .mp4 name too.

Offline

#12 2019-03-04 17:04

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename file exactly like another file with a different extension

HexaPro wrote:

I have folder for each movie and, in each folder there's a .mp4 and .srt file.
How do I rename the .srt exactly like the .mp4 name so that I can load the .srt automatically whenever I play the .mp4?

HexaPro wrote:

I actually need to match the .srt with the .mp4 in each folder. There's one movie title per folder and some have sub folder too like this:

HexaPro wrote:

And what if I have several video files in one folder, also with it's .srt files.

HexaPro wrote:

So I really need to copy just the .mp4 file name as the .srt file name,

Me think you want:
- for each selected folder
- - - for each MP4
- - - - - take the MP4-Base name
- - - - - If exists a SRT file, Then rename them with same MP4-Base name

Apparently this wouldn't work if you have several MP4s in  one single folder, or you must find a common pattern of both MP4 and SRT a program is able to detect them as a pair.

And since we can not tell ReNamer to work on sub folder level X only, you have to select exactly each folder with MP4-SRT pairs and start the renaming.



Perhaps we will find a solution for you...
 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#13 2019-03-05 02:04

HexaPro
Member
Registered: 2019-03-03
Posts: 15

Re: Rename file exactly like another file with a different extension

Stefan wrote:

Me think you want:
- for each selected folder
- - - for each MP4
- - - - - take the MP4-Base name
- - - - - If exists a SRT file, Then rename them with same MP4-Base name

Exactly, how to do just that?
How the read file name of just the .mp4 and then copy it if there's a .srt file in the folder.

Stefan wrote:

Apparently this wouldn't work if you have several MP4s in  one single folder, or you must find a common pattern of both MP4 and SRT a program is able to detect them as a pair.

I think this one just for a 'Movie', not a TV series that has many .mp4 and .srt at the same folder.
The TV series can wait after I know exactly what to do about the 'Movie'

Stefan wrote:

And since we can not tell ReNamer to work on sub folder level X only, you have to select exactly each folder with MP4-SRT pairs and start the renaming.

Got it.

Offline

#14 2019-03-05 20:44

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename file exactly like another file with a different extension

So, now to this!


I have tested that >> http://www.den4b.com/forum/viewtopic.php?pid=1425#p1425


and it works for single MP4/SRT pairs, even in sub and subsub folders.

How to:
- save below code into ReNamer folder as "test.pas" text file, see
http://www.den4b.com/wiki/ReNamer:Rules:PascalScript

- have a backup!!!
- select your main folder and load all files (with only one pair of MP4/SRT files)
- add this script as PascalScript-Rule
- click [Preview]
- the base name of ALL files should be shown as same as like the MP4
(that last could be changed to rename only base of SRT files, for example)


//  den4b 2007-10-21 http://www.den4b.com/forum/viewtopic.php?pid=1425#p1425
// Stefan 2019-03-05 http://www.den4b.com/forum/viewtopic.php?pid=10748#p10748
// Rename Buddy files with name of Master file, f.ex. for MP4 / SRT pairs.
// For each file:
// ---- Scan dir of current file for all MP4 files (MASTER_MASK), first found is MASTER-file.
// ---- If current file is not the MASTER file itself, then rename its base name to base name of MASTER
// ------- (that last could be changed to rename only base of SRT files, for example)

const
  MASTER_MASK = '*.mp4';

var
  MasterFile: WideString;

function FindMasterFile(const Dir: WideString): WideString;
var
  Files: TWideStringArray;
begin
  Result := '';
  SetLength(Files, 0);
  WideScanDirForFiles(Dir, Files,False, False, False, MASTER_MASK); //get all files into array
  if Length(Files) > 0 then
    Result := Files[0]; //get first file from array
end;

begin
  MasterFile := FindMasterFile(WideExtractFileDir(FilePath));
  //  showmessage(MasterFile +#13#10+ FilePath);
  //if a MasterFile is found:
  if MasterFile <> '' then
  //if the current file is not the MasterFile:
  if MasterFile <> FilePath then
  begin
    MasterFile := WideExtractBaseName(MasterFile);
    FileName := MasterFile + WideExtractFileExt(FileName);
  end;
end.
//    



HTH? big_smile


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#15 2019-03-06 02:45

HexaPro
Member
Registered: 2019-03-03
Posts: 15

Re: Rename file exactly like another file with a different extension

Stefan wrote:

...
<full quoting removed>

HTH? big_smile

Wow wow wow... It works, yay! Thank you so much.
I'm trying to understand the code even tho I don't understand some of them LOL, since I don't understand programming.

So now what I should do if I want to rename a TV Series that has many .mp4 and .srt in one folder. The .srt has some phrase that match the .mp4 but exactly the same. Is there already a thread for that kind of solution? Or do you have a better idea?

Offline

#16 2019-03-09 05:13

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename file exactly like another file with a different extension

HexaPro wrote:

So now what I should do if I want to rename a TV Series that has many .mp4 and .srt in one folder.
The .srt has some phrase that match the .mp4 but exactly the same.

Me think you missed there a "not", isn't it?



If you have several MP4/SRTs in  one single folder, you must find a common pattern
of both MP4 and SRT a program is able to detect them as a pair.
- common strings in file name
- common time stamp
- just the order in folder? Just the next SRT after each MP4 is the right one?

Seems to me like that is rather a task for a human being?






 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#17 2019-03-09 05:30

HexaPro
Member
Registered: 2019-03-03
Posts: 15

Re: Rename file exactly like another file with a different extension

Stefan wrote:

If you have several MP4/SRTs in  one single folder, you must find a common pattern
of both MP4 and SRT a program is able to detect them as a pair.
- common strings in file name
- common time stamp
- just the order in folder? Just the next SRT after each MP4 is the right one?

- I think common strings in file name exist for each pair, even tho not exactly the same. That's why I want to rename them .srt
- I don't think they have a common time stamp.
- They usually line in order, both the .mp4 and the .srt since they usually start with something like S01E01 through S01-E16.

Stefan wrote:

Seems to me like that is rather a task for a human being?

LOL, I'm just trying to be lazy.

Offline

#18 2019-03-09 15:17

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename file exactly like another file with a different extension

HexaPro wrote:

.. they usually start with something like S01E01 through S01-E16.

Then they have something common!?

We still lagging your example folder content with multiple MP4/SRTs...

Please provide a list of your real world file names (maybe ten to twenty), in every (or at least the most) possible occurrence.
(try cmd.exe "command line interpreter" in main folder with: DIR /B /S>"__List.txt",
next copy and paste some relevant lines from the "__List.txt" here to the forum)
You may want to mask original words by concealing them, but keep each other detail, like digits,
parentheses, brackets, spaces, dots, hyphen, underscores, commas, original lengths...
Thanks.




 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#19 2019-03-12 09:31

HexaPro
Member
Registered: 2019-03-03
Posts: 15

Re: Rename file exactly like another file with a different extension

HexaPro wrote:

.. they usually start with something like S01E01 through S01-E16.

Stefan wrote:

Then they have something common!?

We still lagging your example folder content with multiple MP4/SRTs...

Please provide a list of your real world file names (maybe ten to twenty), in every (or at least the most) possible occurrence.
(try cmd.exe "command line interpreter" in main folder with: DIR /B /S>"__List.txt",
next copy and paste some relevant lines from the "__List.txt" here to the forum)
You may want to mask original words by concealing them, but keep each other detail, like digits,
parentheses, brackets, spaces, dots, hyphen, underscores, commas, original lengths...
Thanks.

Here's some example

Sample

Sample

Sample

Last edited by HexaPro (2019-03-12 09:46)

Offline

#20 2019-03-12 10:03

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename file exactly like another file with a different extension

In text form please (for us to create our own test files to test our solution on)

You can just paste it in here.



 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB