Page 1 of 1

Working script to get property from 1 file & suffix to dir

Posted: 16 Sep 2016 18:41
by Jerry
I'm looking for a working script, or a reusable fragment of a working script (not just an outline of steps), that does the following (which I can then edit further for my particular needs):
  • For each folder in a selection of folders:
    1. Go to any file in the folder.
    2. Extract a property from the file.
    3. Suffix the property value to the parent folder
    4. Repeat with the next folder in selection.
The property is just extracted from one file in each folder, under the assumption that all files in the folder have the same value for the same property. In my case, I want the prop:#audio.bitrate (just the digits) suffixed as "MP3@xxx" to the parent folder.

Re: Working script to get property from 1 file & suffix to d

Posted: 16 Sep 2016 19:01
by highend

Code: Select all

    foreach($folder, <get SelectedItemsPathNames |>) {
        if (exists($folder) != 2) { continue; }
        $bitrate = regexreplace(property("#audio.bitrate", gettoken(listfolder($folder, , 1), 1, "|")), "[^0-9]");
        if !($bitrate) { continue; }
        $base = gpc($folder, "component", -1);
        renameitem("$base MP3@$bitrate", $folder);
    }

Re: Working script to get property from 1 file & suffix to d

Posted: 16 Sep 2016 19:35
by Jerry
Works perfectly, highend. I just changed it to include a "*.mp3" pattern in the call to listfolder() since there are other non-audio files usually present. Thank you very much!