CSV rename script

Discuss and share scripts and script files...
Post Reply
Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

CSV rename script

Post by Elpolloloco »

Is there any script to rename files based on 2 columns in a csv or xlsx file? One column actual name second column new name.

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: CSV rename script

Post by highend »

Not that I am aware of. But it surely doable. But with the spare information here (which columns? should the .csv / .xlsx files be renamed themselves or do these files contain files that should be renamed?) rather not...
One of my scripts helped you out? Please donate via Paypal

Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

Re: CSV rename script

Post by Elpolloloco »

I dont need the csv or xlsx to be renamed, only files that match the columns.

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: CSV rename script

Post by highend »

A real world example?
One of my scripts helped you out? Please donate via Paypal

Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

Re: CSV rename script

Post by Elpolloloco »

Oldname, newname
File04.pdf,newnamefile04.pdf
0099file.zip,newname.zip

That folder will have many files, i only want the files File04.pdf and 0099file.zip to be renamed to newnamefile04.pdf and newname.zip respectively

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: CSV rename script

Post by highend »

Code: Select all

    end (gpc(<curitem>, "ext") UnLikeI "csv"), "No .csv file selected, aborted!";

    $srcFiles = "";
    $dstFiles = "";
    $lines    = readfile(<curitem>);
    foreach($line, $lines, <crlf>, "e") {
        $src = gettoken($line, 1, ",", "t");
        if (exists($src) == 1) {
            $srcFiles .= <curpath> . "\" . $src . "|";
            $dstFiles .= <curpath> . "\" . gettoken($line, 2, ",", "t") . "|";
        }
    }
    if ($srcFiles) {
        $srcFiles = trim($srcFiles, "|", "R");
        $dstFiles = trim($dstFiles, "|", "R");
        rename "l", $dstFiles, "p", $srcFiles;
    }
One of my scripts helped you out? Please donate via Paypal

Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

Re: CSV rename script

Post by Elpolloloco »

Wow amazing works perfectly :appl:

Any chance this can be run off a .xlsx file table by specifiyng the columns and table name?

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: CSV rename script

Post by highend »

In theory? Yeah. You would need to unpack the .xlsx file, read the sharedStrings.xml file, parse it and then do the XY renaming stuff.
One of my scripts helped you out? Please donate via Paypal

Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

Re: CSV rename script

Post by Elpolloloco »

Which means im staying with the csv method :lol:

Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

Re: CSV rename script

Post by Elpolloloco »

So this script is ignoring the first line? I dont need to include a first line, what do i do to modify it so it starts in first line

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: CSV rename script

Post by highend »

Where do you see any line in the code that makes you think that it ignores the first line the .csv file?
One of my scripts helped you out? Please donate via Paypal

Elpolloloco
Posts: 14
Joined: 15 Mar 2020 14:54

Re: CSV rename script

Post by Elpolloloco »

My bad, i though it does skip header by default

Post Reply