I have something i want to make with powershell. I’ll try to explain. I have a folder with 70000 files, named 5 numbers 12345 or 54327 ect ect (in fact they are .doc .xls of .pdf but i can’t see).
I also have 1 .csv with 4 columns. “name”, “client-number” ,“the number” of the corresponding file from the folder i mentioned and the “extention”. So i would like to make a script that looks in the .cvs to match the numbers with the files from the folder. On a match it should rename the filename with “bsn+name”. It also has to change the extention of the file with the corresponding extention mentioned in the .csv
So \folderxx\123456 becomes \folderx\123456798clientname.doc
Can this be done? And how do i do this?
I have attempted your problem with limited time available but enjoy something new in PowerShell. Some very experienced scripters who contribute here may pull this apart / modify / improve. I am still learning my way but wanted to try and contribute - or give you something to possibly start with. The below would need testing in your environment and need some error checking wrapped around it. I have made some assumptions on your file format. I have used a C:\temp\files as a location for the files, and a dummy CSV file.
Thank you Andrew. Your answer really helpt me started. I’m new at programming but i got most of it working. But
I also have a column category in my csv. After renaming the file i’d like to move the file to Basefolder$category. I can not get it to work. Can it be done with piping after the rename-item?
you just need to take destination into brackets. and not need to use variables with $() - its need only inside strings
#instead of
$FolderPath + "\" + ($($DB[$i].categorie))
#use
($FolderPath + "\" + $DB[$i].categorie)
#or
(Join-Path $FolderPath $DB[$i].categorie)
#here I show $() usage but i think join-path is better. note the double quotes outside
"$FolderPath\$($DB[$i].categorie)"