Rename to URL

This preset renames files to their target properties. Files that don't have this property will be skipped. The target string will be slightly cleaned up for better readability.

// https://resource.dopus.com/t/rename-to-url/49846
// 2024-03-20

function OnGetNewName(getNewNameData) {
    var otherMeta = getNewNameData.item.metadata.other;
    if (otherMeta.target_type != 'url') return;

    var tmp = String(otherMeta.target);
    var tmpExt = getNewNameData.newname_ext;

    tmp = tmp.replace(/https?:\/\//g, '');
    tmp = tmp.replace(/^ww+\./g, '');
    tmp = tmp.replace(/\.html?$/g, '');
    tmp = tmp.replace(/:/g, '-');
    tmp = tmp.replace(/\//g, '-');
    tmp = tmp.replace(/\?/g, '');
    tmp = tmp.replace(/-+/g, '-');
    tmp = tmp.replace(/-$/g, '');

    tmp = decodeURIComponent(tmp);

    return tmp + tmpExt;
}

Save Rename to URL.orp to   ↓

%appdata%\GPSoftware\Directory Opus\Rename Presets

How to use Rename Presets from this forum

7 Likes

fine!
can you make some update with such link
URL=https://www.translate.ru/%D0%BF%D0%B5%D1%80%D0%B5%D0%B2%D0%BE%D0%B4/%D1%82%D1%83%D1%80%D0%B5%D1%86%D0%BA%D0%B8%D0%B9-%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9
InternetShortcut.url.txt (185 Bytes)

Sure :sunglasses:

1 Like

Just one line added! amazing!

Lucky punch :smiley: