That was a great help, thanks for that. I have changed the script slightly:
Get-ChildItem -recurse -include *.* | % { Rename-Item -WhatIf $_($_.Name
-replace 'pdf.*?pdf$') }
Do you know if it would be possible to extract the file extension off the
end of the file name? Due to the files being renamed are of different
extensions, it would be handy if the script logically knew the extension and
stored it into a variable. So, does anyone know how to extract the last 4
characters and store it in a variable?
"Tao Ma" wrote:
> Hi robm_jnb,
>
> Try:
> Get-Item *.pdf | % { Move-Item -Whatif $_ ($_.Name -replace 'pdf.*?pdf$') }
>
> If it works like you wish, remove '-Whatif' to let it get the work done.
>
> "robm_jnb" <robm_jnb@xxxxxx> 脨麓脠毛脧没脧垄脨脗脦脜:16B5EFB4-CB81-4D44-BFEB-1B31E9B44B5F@xxxxxx
> > Hi everyone,
> >
> > I have a problem in that I need to compose a PowerShell script to rename
> > about 200 files. These files are the in the example format:
> >
> > sample pdf document.pdf_(2008-05-24_04-16-15_DEL_T).pdf
> >
> > Basically I need the script to just leave the file name, and get rid of
> > the
> > jibberish. So after running it should rename the file to:
> >
> > sample pdf document.pdf
> >
> > I have looked at both regular expressions and the trim function, but have
> > not got very far. I would really appreciate any help that people can give.
> >
> > Thanks in advance. >
>
>