![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Ren file with variable 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! |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Ren file with variable Try this: $file = "history.doc" ren $file ((get-item $file).name -replace '\.', ".$(get-date -uFormat %m%d%y).") -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Ren file with variable Sorry, missed the 4 digit year format, capitalize the 'y' %m%d%Y -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Ren file with variable 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! > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Can not Creat work file,check temp environment variable | Microsoft Office | |||
| $Variable Is In {1,2,3,4} | PowerShell | |||
| Refresh on Reading more than one variable from a Text file | VB Script | |||
| How to set errorlevel env variable properly from a simple batch file: Answered | Vista General | |||
| How can I ensure that a variable is a built-in powershell variable? | PowerShell | |||