0

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\

bac.accdb
KFBAROPN.SAVEFILE.CSV
KFBARTRD.SAVEFILE.CSV

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.

3
  • 3
    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. May 21, 2013 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, 2013 at 15:11
  • @user225817 - Do some research and come back and update your question..
    – Ramhound
    May 21, 2013 at 16:09

1 Answer 1

1

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"
6
  • 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, 2013 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, 2013 at 14:08
  • Error message is "%%i was unexpected at this time."
    – user225817
    May 24, 2013 at 14:10
  • on the cmd prompt the for loop variables get only one %, eg. %i !
    – Endoro
    May 24, 2013 at 14:13
  • Endoro. What should i put in place of "dir" in the script line you provided ?
    – user225817
    May 24, 2013 at 16:19

Not the answer you're looking for? Browse other questions tagged .