newbie here. I am trying to write a PowerShell script to:
- loop through all files in directory
- List item
Get all .pdf files ONLY
Rename them-the file names are long - over 30 chars -They contain 2 numbers which I need to extract -Example:
Cumulative Update 11 for Microsoft Dynamics NAV 2018 (Build 25480).pdf -> RESULT : = 18CU11.pdf
I tried examples from bunch of sites and I can't seem to even loop successfully. Either get an error - that path doesn't exist or that can't rename files as somehow loop gets a filepath and that I can't rename
Get-ChildItem "C:\Users\******\Desktop\PowerShell Practice" -Filter *.pdf | #create list of files
ForEach-Object{
$oldname = $_.FullName;
$newname = $_.FullName.Remove(0,17);
#$newname = $_.FullName.Insert(0,"CU")
Rename-Item $oldname $newname;
$oldname;
$newname; #for testing
}
That's just latest attempt, but any other ways of doing it will be fine - as long as it does the job.