Page 1 of 1

rename files belong to directories

Posted: 07 Dec 2020 14:09
by galtar53
Hello everyone, I want to add the directory name to the name of the files. see the attached example.
cordially

Re: rename files belong to directories

Posted: 07 Dec 2020 14:32
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);
    }

Re: rename files belong to directories

Posted: 07 Dec 2020 15:30
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

Re: rename files belong to directories

Posted: 07 Dec 2020 15:39
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);
        }
    }