1

I am wanting to rename a file name in a document library called "RenameAFile". Currently have the following file called "UD-PD-Documentattion.xlsx"

and I want add "DN" before the file name "UD-PD-Documentattion.xlsx".

Output:

DN-UD-PD-Documentattion.xlsx

Is this possible? Would anyone able to help?

Thanks

  • when you want to change the file, once it uploaded or during the upload process or what? – Waqas Sarwar MVP Dec 6 '18 at 22:52
0

I manage to figure it out.

$Web = Get-SPWeb "http://yoursite.com/documentlib"
$DocLib = $Web.Lists["RenameAFile"]          
foreach($ListItem in $DocLib.Items)
   {    
         $ListItem.File.CheckOut()
             $ListItem["Name"] = "DN-"+$ListItem["Name"]
             $ListItem["Title"] = "Add DN"
             $ListItem.Update()
         $ListItem.File.CheckIn("File Name Updated")     
   }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.