Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

This question already has an answer here:

I have a directory which consists of many files as below. But my requirement is to change the .CSV filenames only.

Name of the Dir: c:\files\


I have to remove the "."(dot) and replace with hypen(-) . Can you please provide me with a windows batch script file(eg: abc.bat) and also let me know how to schedule to run this file in windows?

I am very new to windows script and your help is much appreciated.

share|improve this question

marked as duplicate by Karan, Tog, Brad Patton, Journeyman Geek, Tanner Faulkner May 29 '13 at 14:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Does it really need to be batch? PowerShell is really the standard on Windows now, and is the better route for readability, sustainability and its easier to learn. – AthomSfere May 21 '13 at 15:03
Ok. I didn't know anything about Windows shell or Powershell. Can you please also let me know how to execute and schedule the powershell script . Please help me with the script. I will try it. Many Thanks VJ – user225817 May 21 '13 at 15:11
@user225817 - Do some research and come back and update your question.. – Ramhound May 21 '13 at 16:09

try this (cmd shell):

for /f "tokens=1*delims=." %i in ('dir /a-d/b *.*.csv') do @ren "%~i.%~j" "%~i-%~j"

.. and for use in a batch script:

for /f "tokens=1*delims=." %%i in ('dir /a-d/b *.*.csv') do ren "%%~i.%%~j" "%%~i-%%~j"
share|improve this answer
Many Thanks. I will try. – user225817 May 22 '13 at 8:01
Hi I placed 4 files in the directory Test. 1. J.BODPOS.20130516.CSV 2. J.BODTRADES.20130516.CSV 3. KFBAROPN.SAVEFILE.CSV 4. KFBARTRD.SAVEFILE.CSV. Created a batch script filen.bat, with the code inside as for /f "tokens=1*delims=." %%i in ('C:\test/a-d/b ..CSV') do ren "%%~i.%%~j" "%%~i-%%~j" and when i run getting error as "C:\test>filen.bat 'filen.bat' is not recognized as an internal or external command, operable program or batch file." – user225817 May 22 '13 at 8:12
Hi I tried this from the cmd prompt and received error . Can you please help me on this. --- for /f "tokens=1*delims=." %%i in ('C:\Documents and Settings\v\ACCESS RECS\test\ /a-d/b ..csv') do @ren "%%~i.%%~j" "%%~i-%%~j" – user225817 May 24 '13 at 14:08
Error message is "%%i was unexpected at this time." – user225817 May 24 '13 at 14:10
on the cmd prompt the for loop variables get only one %, eg. %i ! – Endoro May 24 '13 at 14:13

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