this should work
$fname = "history.txt"
$pfx = [System.IO.Path]::GetFileNameWithoutExtension($fname)
## get the date
$date = get-date -uformat %m%d%y
$date = $pfx + "." + $date
if ([System.IO.File]::Exists($fname))
{
$fext = [System.IO.Path]::GetExtension($fname)
$newfile = $date + $fext
trap {"unable to rename file"} [System.IO.File]::Move($fname, $newfile)
}
else
{
"file does not exist"
break
}
--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog:
http://richardsiddaway.spaces.live.com/
PowerShell User Group:
http://www.get-psuguk.org.uk
"ryanlsanders@gmail.com" wrote:
> I have a file. history.doc I want to rename it to history.
> 08172007.doc or even 08172007.history.doc
>
> I have tried this command
>
> ren hisotry.doc -newname"$get-date -uFormat %m%d%y"+"history.doc"
>
> I can not figure out the syntax for variables....
>
> Please help
>
> Thank!
>
>