#1 : 30/01-20 15:23 Mario Alvarez
Posts: 30
|
Is it possible to rename a file with the name of other file in the same folder (they both have different extensions)?
Example: I have 3 files in the same folder: Name of the Movie (2009).mp4 Name of the Movie (2009)-spa.srt English.srt How can I rename the file "English.srt" to "Name of the Movie (2009)-eng.srt? Note: the name of the folder is "Name of the Movie (2009_name of the director" and I don't want to change it. Thank you very much. |
#2 : 30/01-20 22:29 David Lee
Posts: 1125
|
I'm assuming that you mistyped the folder name and it should have been "Name of the Movie (2009)_name of the director".
Try using two Replace methods in the same method list: 1) Text to be replaced: English.srt Replace with: <DirName>.srt Use regular expressions: Not checked Apply to: Name and extension 2) Text to be replaced: _.*\.srt Replace with: -eng.srt Use regular expressions: Checked Apply to: Name and extension Drag all your folders into the List and select Add the files in the folders Each instance of "English.srt" will be renamed based on its respective folder name. |
#3 : 13/04-20 21:27 Mario Alvarez
Posts: 30
|
Reply to #2:
Thank you very much, David! It worked perfectly. Best regards, Mario |
#4 : 20/04-20 21:20 Joel Wangolo
Posts: 1
|
It's very possible I just did this
backup.js backup.py same folder |
#5 : 19/05-20 11:15 Mario Alvarez
Posts: 30
|
I have another question regarding the same issue:
What if I don´t want to use the folder's name?. I mean, is it possible to rename one file with the same name of other file (with different extension) in the same folder, but not using the folder's name? Thank you in advance, Mario |
#6 : 19/05-20 13:51 David Lee
Posts: 1125
|
Reply to #5:
It isn't obvious what you want to do. Please try to be more specific and provide an example. |
#7 : 19/05-20 15:53 Mario Alvarez
Posts: 30
|
Reply to #6:
OK. I'll put the next example: I have 3 files in the folder named "Best Movies of 1999": 1) The Matrix (1999).mp4 2) The Matrix (1999)-spa.srt 3) English.srt How can I rename the file "English.srt" to "The Matrix (1999)-eng.srt"? Thank you very much. Mario |
#8 : 20/05-20 12:28 David Lee
Posts: 1125
|
Reply to #7:
You still haven't sufficiently defined your problem. I'm assuming that you have a number of folders each containing three files : 1) MovieName.mp4 2) MovieName-spa.srt 3) English.srt and you wish to rename each instance of English.srt to MovieName-eng.srt If that is correct then drag the contents of all your folders into the List and use the Script method as follows... In the Pre batch script: var names = {}; n = app.itemCount; for (j=0; j<n; j++) { item = app.getItem(j); if (item.ext == '.mp4') { names[item.path] = item.name; } } and in the main script window: if (item.name == 'English') { return names[item.path] + '-eng'; } The Pre batch script iterates through all the filenames in the list and saves the filename of each mp4 file into the array "names", indexed by the file-path. This array is then available to the main script, which renames all files in the list that are named "English" to the value saved in the array element of "names" indexed by the file-path corresponding to each instance of the filename "English". |
#9 : 20/05-20 15:32 Abby
Posts: 3
|
Reply to #2:
I have a similar(ish) issue. I am trying to rename a large batch of files, using the list replace method. There are many files within the batch which have the same file name but with different extensions eg. File_01.xlsm & File_01.pdf File_02.xlsm & File_02.pdf etc The renamer is not allowing me to progress with the renaming because the files have the same name (despite having different extensions). I don't want the files to have different names as they are essentially the same document. Is there any way around this? |
#10 : 21/05-20 19:50 Mario Alvarez
Posts: 30
|
Reply to #9:
Thank you very much, David! It worked perfectly. I don't know how to work with the Script Method, but I copied exactly the code you wrote and it did the job. |
#11 : 21/05-20 22:25 Mario Alvarez
Posts: 30
|
Reply to #10:
I have another question. Before I run the script method to rename the English.srt file with the same name of the mp4 file, I have to rename properly the latter. But I want to rename three files in each folder at the same time, and the problem is that two of them have the same extension srt. I’ll explain better: I have several folders and in each of them there are 3 files: 1) Movie.Name.1999.1080p.BluRay.x264.mp4 2) Movie.Name.1999.720p.Xvid.spa.srt 3) Movie.Name.1080p.srt I know how to rename the first two files, like this: 1) Movie Name (1999).mp4 2) Movie Name (1999).spa.srt But I want to rename, at the same time, the third file (english subtitle) to: 3) Movie Name (1999).eng.srt Is this possible? How can I do that? Note: I don't want to use the folder names, because they are not similar to the name of the files that I want. Thank you in advance, Mario |
#12 : 22/05-20 00:22 David Lee
Posts: 1125
|
Reply to #11:
We could rename all the files in a single Script method but If you are already successfully renaming the first two files in each folder then just add the script method at the end of the existing batch. We will need to makes some changes to the previous solution - as follows: Pre batch script var names = {}; n = app.itemCount; for (j=0; j<n; j++) { item = app.getItem(j); if (item.ext == '.mp4') { names[item.path] = item.newBasename; } } Main script... if (item.newName.match(/^(?!.*spa).*\.srt$/)) { return names[item.path] + '.eng'; } Explanation... In the Pre batch script: item.name returns the ORIGINAL filename so we need to replace it with item.Newbasename: In the main script: item.newName returns the new filename together with the extension The match method returns TRUE if the string (item.newName) matches the specified pattern The pattern is a Regular Expression (defined by enclosing in a pair of forward slashes "/.../") that specifies that the string must end with ".srt" but must not contain "spa". (Note that this Regex uses a "negative lookahead", which is not included in the introduction in the User Guide - Google is your friend!). JavaScript and Regular Expressions are daunting at first but fairly straightforward once you get the hang of them - I had no experience of either when I first started playing with Advanced Renamer a short while ago. The User Guide will get you started: www.advancedrenamer.com/user_guide/method_script www.advancedrenamer.com/user_guide/example_scripting www.advancedrenamer.com/user_guide/regular_expresions For more advanced assistance a Google search is the best plan. I usually find that hits at www.w3schools.com are the most helpful for JavaScript information. |
#13 : 22/05-20 15:14 David Lee
Posts: 1125
|
Reply to #12:
Mario, Just for fun - here's an all-in-one script that will rename all three files in one method... Pre batch script: var names = {}; n = app.itemCount; for (j=0; j<n; j++) { item = app.getItem(j); if (item.ext == '.mp4') { name = item.newName.match(/(^.*?)\.(\d{4})/); names[item.path] = name[1] + ' (' + name[2] + ')'; } } Main script: suffix = ''; if (item.ext != '.srt') { suffix = ''; } else if (item.newBasename.match(/.*\.spa$/)) { suffix = '.spa'; } else { suffix = '.eng'; } return names[item.path] + suffix; |
#14 : 22/05-20 21:32 Mario Alvarez
Posts: 30
|
Reply to #13:
Thank you very much again, David. Thanks for your clear explanation, your attention, your quick response and your time. You are really a very good teacher. All my gratitude to you. I'll try to learn more about Regex, and maybe also about JavaScript. Sorry for my poor english. Best regards, Mario |
#15 : 23/05-20 17:18 Mario Alvarez
Posts: 30
|
Reply to #14:
Sorry, but I have another question regarding the script you wrote. The script works fine for mp4 files, but in some folders there are mkv or avi files (only one of them in each folder). What can I do in those cases? Thank you for your attention. Mario |
#16 : 03/06-20 13:25 David Lee
Posts: 1125
|
Reply to #15:
I'm assuming that the folders containing mkv or avi files are otherwise the same as the mp4 folders - ie they also contain .srt and spa.srt files and you wish to rename them in the same way. if so then all you need to do is add OR conditions (||) to the "if " statement in the Pre batch script: var names = {}; n = app.itemCount; for (j=0; j<n; j++) { item = app.getItem(j); ext = item.ext; if (ext == '.mp4' || ext == '.mkv' || ext == '.avi') { name = item.newName.match(/(^.*?)\.(\d{4})/); names[item.path] = name[1] + ' (' + name[2] + ')'; } } |
#17 : 09/06-20 12:35 Mario Alvarez
Posts: 30
|
Reply to #16:
Thank you very much again, David! |