rename files belong to directories

Discuss and share scripts and script files...
Post Reply
galtar53
Posts: 18
Joined: 19 Nov 2019 16:33

rename files belong to directories

Post by galtar53 »

Hello everyone, I want to add the directory name to the name of the files. see the attached example.
cordially

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

Re: rename files belong to directories

Post by highend »

There is no attached example...

Code: Select all

    $items = <get selecteditemspathnames <crlf>>;
    foreach($item, $items, <crlf>, "e") {
        renameitem(gpc($item, "base") . " [" . gpc($item, "component", -2) . "]", $item);
    }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

galtar53
Posts: 18
Joined: 19 Nov 2019 16:33

Re: rename files belong to directories

Post by galtar53 »

it's wonderful but I wanted to do this on several directories at the same time, adding their names to the prefix of each file inside without opening the directory. while selecting the directory only.
thank you very much

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

Re: rename files belong to directories

Post by highend »

Code: Select all

    $folders = <get selecteditemspathnames <crlf>>;
    foreach($folder, $folders, <crlf>, "e") {
        if (exists($folder) != 2) { continue; }

        $base = gpc($folder, "component", -1);
        $files = listfolder($folder, , 1, <crlf>);
        foreach($file, $files, <crlf>, "e") {
            renameitem($base . " - " . gpc($file, "file"), $file);
        }
    }
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Post Reply