Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

Example:

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 professional 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.

add comment

1 Answer

@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
add comment

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