Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There are lots of questions asked about batch renaming already, but I think my problem is a bit different. I need to rename a lot of files by switching around the components of the filename.


Original filename: BGP-2012-LOG-KTH-01.doc New filename: 2012-BGP-KTH-LOG-01.doc

The different parts of the filename are delimited by dashes. Been ages since I ever had to script anything, I've never been good at it anyway. Hopefully someone can help. I'm on windows 7, so powershell, or vbscript may be the easiest (but then I'm no expert).

share|improve this question

closed as off topic by Zoredache, Tom O'Connor, Magellan, mdpc, Scott Pack Nov 1 '12 at 17:55

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

@echo off

for /f "tokens=1-5 delims=-" %%a in ('dir /b "C:\Users\*.doc"') do (
    ren C:\Users\%%a-%%b-%%c-%%d-%%e %%b-%%a-%%d-%%c-%%e
share|improve this answer

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