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

Discuss and share scripts and script files...
Post Reply
Jerry
Posts: 805
Joined: 05 May 2010 15:48
Location: The UnUnited States of America

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

Post 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.
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB.

highend
Posts: 13308
Joined: 06 Feb 2011 00:33

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

Post 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);
    }
One of my scripts helped you out? Please donate via Paypal

Jerry
Posts: 805
Joined: 05 May 2010 15:48
Location: The UnUnited States of America

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

Post 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!
Running on Windows 10 Pro 64-bit quad-core ASUS G752-VY notebook with 64 GB RAM, over 26 external USB3 drives attached via multiple powered hubs with letters and mount points, totaling 120+ TB.

Post Reply