CSV rename script
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
CSV rename script
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.
Re: CSV rename script
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
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
Re: CSV rename script
I dont need the csv or xlsx to be renamed, only files that match the columns.
Re: CSV rename script
A real world example?
One of my scripts helped you out? Please donate via Paypal
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
Re: CSV rename script
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
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
Re: CSV rename script
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
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
Re: CSV rename script
Wow amazing works perfectly
Any chance this can be run off a .xlsx file table by specifiyng the columns and table name?
Any chance this can be run off a .xlsx file table by specifiyng the columns and table name?
Re: CSV rename script
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
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
Re: CSV rename script
Which means im staying with the csv method
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
Re: CSV rename script
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
Re: CSV rename script
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
-
- Posts: 14
- Joined: 15 Mar 2020 14:54
Re: CSV rename script
My bad, i though it does skip header by default