How to use contents of a field in filenames

If you need help on how to use the program
Post Reply
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

How to use contents of a field in filenames

Post by boristhecat »

I have about 6500 entries in AMC. They're all films and all have the year the film was released in the field named 'Year'. What I would like to do is include that date into the filename.
So, 'Batteries not included.mp4' in the original title, would become 'Batteries not included (1987).mp4'.
I have managed to name all the files on the disks in this way, exporting the names and year fields and then using Python to change the file names on disk. But I would love to be able to change the film title in the program too.
Is it possible?
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: How to use contents of a field in filenames

Post by antp »

It should be easy to do with the script engine of AMC:

Code: Select all

program AppendYear;
var
  name, ext: string;
begin
  ext := ExtractFileExt(GetField(fieldFilePath));
  name := ChangeFileExt(GetField(fieldFilePath), '') + ' (' + GetField(fieldYear) + ')' + ext;
  SetField(fieldFilePath, name);
end.
Untested, if it does not work it should be something close to that.
Assuming the file path is in the appropriate field, otherwise change the constant "fieldFilePath" to something else.
For more info about functions in the script engine, see in Help -> Technical info -> Script
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

That means absolutely nothing to me lol but thanks, I shall check in help and see if I can figure something out. :clapping:
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

I am really struggling here. Is the script editor the one you access from the folder full of internet scripts? I tried making a new file and input the details you gave me but no matter how I juggle it it just keeps saying there is a script editor.
Is there any way I can access a simple text list of all film entries in the database? Clearly the scripting isn't going to work but if I can access the filenames I could do it from there?
fulvio53s03
Posts: 745
Joined: 2007-04-28 05:46:43
Location: Italy

Re: How to use contents of a field in filenames

Post by fulvio53s03 »

... sorry... do you want to add year in file names (in your folder) or will you add year in field "file path" of your catalog? :??:
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: How to use contents of a field in filenames

Post by antp »

What is the problem with the script exactly?
You to go Tools -> Scripting, click the "Editor" tab and then the "new" icon (white paper sheet) and paste the script there.
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

fulvio53s03 wrote: 2024-09-16 16:29:04 ... sorry... do you want to add year in file names (in your folder) or will you add year in field "file path" of your catalog? :??:
Yeah so in the 'Original Title' field the films name appears when you import. The date appears in the 'date' field. I would love the film title to be in the format 'title and year'. So for example, "Great film (2024)". But I can't figure out how to get the year to appear in parentheses after the title. That's one goal.
But also I want to name the files on disk in the same format as they are in AMC. Currently it has taken me weeks to fudge together a working script to achieve this but it means exporting Title and Year from AMC, then taking the Tree list from the disk holding the films and add that list to the csv file produced by AMC. So now I have 3 columns in the csv: the disk generated list of files, the amc generated list of titles, and the years of all titles. I then have to correct all the mistakes where films don't line up because the order they are listed is different in Windows, as it is in AMC. Once I get them all lined up properly, then I now have some scripts that can compare the titles to those on disk, and insert the date like this (2024) before the file extension. So that part is easy. The difficult and time consuming part is getting the two lists to match.
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

antp wrote: 2024-09-18 07:19:07 What is the problem with the script exactly?
You to go Tools -> Scripting, click the "Editor" tab and then the "new" icon (white paper sheet) and paste the script there.
All it ever says to me is "Error in statement at line 2" which is 'program AppendYear;'
fulvio53s03
Posts: 745
Joined: 2007-04-28 05:46:43
Location: Italy

Re: How to use contents of a field in filenames

Post by fulvio53s03 »

boristhecat wrote: 2024-09-24 19:31:12
Yeah so in the 'Original Title' field the films name appears when you import. The date appears in the 'date' field. I would love the film title to be in the format 'title and year'. So for example, "Great film (2024)". But I can't figure out how to get the year to appear in parentheses after the title. That's one goal....
First of all, save your AMC archive using a new name.
After this create a new script: Add_date

Code: Select all

(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=fulvio53s03
Title=ADDdate
Description=aggiunge data al titolo originale
Site=
Version=0.1
Requires=3.5
Comments=
License=GPL
GetInfo=1
RequiresMovies=1
[Options]
[Parameters]
***************************************************)
program ADDdate;
uses
  StringUtils7552;
var
  title_orig, year_orig: string;
begin
    title_orig  := getfield(fieldoriginaltitle);
    year_orig := getfield(fieldyear);
    title_orig := title_orig + ' (' + year_orig + ')';
    SetField(fieldoriginalTitle, title_orig);
end.
Execute it and take a look to your new archive. If it is OK, we have resolved the first step of our work.
;)
antp
Site Admin
Posts: 9636
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Re: How to use contents of a field in filenames

Post by antp »

boristhecat wrote: 2024-09-24 19:39:37 All it ever says to me is "Error in statement at line 2" which is 'program AppendYear;'
That line should be the first line. Maybe I should have said that you can replace the contents by the one I provided ;)
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

fulvio53s03 wrote: 2024-09-25 05:30:16
boristhecat wrote: 2024-09-24 19:31:12
Yeah so in the 'Original Title' field the films name appears when you import. The date appears in the 'date' field. I would love the film title to be in the format 'title and year'. So for example, "Great film (2024)". But I can't figure out how to get the year to appear in parentheses after the title. That's one goal....
First of all, save your AMC archive using a new name.
After this create a new script: Add_date

Code: Select all

(***************************************************
Ant Movie Catalog importation script
www.antp.be/software/moviecatalog/
[Infos]
Authors=fulvio53s03
Title=ADDdate
Description=aggiunge data al titolo originale
Site=
Version=0.1
Requires=3.5
Comments=
License=GPL
GetInfo=1
RequiresMovies=1
[Options]
[Parameters]
***************************************************)
program ADDdate;
uses
  StringUtils7552;
var
  title_orig, year_orig: string;
begin
    title_orig  := getfield(fieldoriginaltitle);
    year_orig := getfield(fieldyear);
    title_orig := title_orig + ' (' + year_orig + ')';
    SetField(fieldoriginalTitle, title_orig);
end.
Execute it and take a look to your new archive. If it is OK, we have resolved the first step of our work.
;)
Simple and perfect. Than you.
One small thing, it adds a date to a title even if that title already has the date added, which many hundreds of my files do. So I did a script to delete any date in the title field, then used your script to add the date in. I tried to make one that would detect a date and ignore that field and add the date to ones that did not have one. Sadly for some reason that didn't work buy hey ho, I got what I wanted in the end.

So here's another task. I am not going to see if I can do the same thing with the JPG's in the catalog. Wish me luck!
fulvio53s03
Posts: 745
Joined: 2007-04-28 05:46:43
Location: Italy

Re: How to use contents of a field in filenames

Post by fulvio53s03 »

Your catalog is saved as xml? Pictures are in a separate folder?
please extract some titles from your catalog, save them in a next catalog and send it to me (with related images), so that I can well understand and resolve your questions.
:hihi:
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

fulvio53s03 wrote: 2024-09-28 13:11:34 Your catalog is saved as xml? Pictures are in a separate folder?
please extract some titles from your catalog, save them in a next catalog and send it to me (with related images), so that I can well understand and resolve your questions.
:hihi:
My catalog is just saved as catalog? All the images are in there as JPG's. The catalog database also resides in the catalog folder. What I am going to try is to get the image corresponding to each entry, is named in the exact same format as the movie title in the database. ([title][date]). There's no purpose to this other than to be organised. I've got a copy of my whole program and have been testing on it and so far (touch wood) the title renaming has worked perfectly.
fulvio53s03
Posts: 745
Joined: 2007-04-28 05:46:43
Location: Italy

Re: How to use contents of a field in filenames

Post by fulvio53s03 »

boristhecat wrote: 2024-09-28 13:35:18 My catalog is just saved as catalog
Very well, your problem seems to be resolved. :grinking: :)
Will you tell me if your catalog is a file "xyz.amc" and images are contained within it?
Where did you changed the .jpg name? in a field of the catalog? in folder? in both of them?
I'm really interested, it cold be useful to me to know your work's final steps.
:)
boristhecat
Posts: 68
Joined: 2015-06-30 22:25:21

Re: How to use contents of a field in filenames

Post by boristhecat »

fulvio53s03 wrote: 2024-09-28 13:50:21
boristhecat wrote: 2024-09-28 13:35:18 My catalog is just saved as catalog
Very well, your problem seems to be resolved. :grinking: :)
Will you tell me if your catalog is a file "xyz.amc" and images are contained within it?
Where did you changed the .jpg name? in a field of the catalog? in folder? in both of them?
I'm really interested, it cold be useful to me to know your work's final steps.
:)
It is indeed a file called movies.amc. It resides in the catalog folder. The images all reside in the catalog folder too.
So far the only way I have to change the .jpg's name is through AMC itself, or manually going into the folder and changing it in windows. I never do it in windows, I do it through amc while it's open. However as there's thousands of entries I wanted a script that would read the date field of each movie, and append the date to the filename of each corresponding jpg file.
I haven't quite got that figured out as yet, I think I will have to export the date field, and use a python script to match the .csv file full of dates to the list of images in the folder, and overwrite the names.
Post Reply