computing
  • 3

Remove Characters From Middle Of a Filename

  • 3

I have the following file name:
0000070970302000-DAIOUTPUTHEADER_CODE_RTM(20100730_RTM_INITIAL1).csv

I would like to execute a batch file to rename all the files in the directory removing the text between the ( ). I would also like to remove all text before the “-”

I believe I need to use a for stmt. Please provide a brief description of what your solution does to fix my problem.

Thank You

Share

1 Answer

  1. Wahines solution helped me solve a problem that I have been working on all day. I am not too sure how it all works, but it does work.

    I have various movie files from my media center. The files needed to be detected as movies instead of TV. The only distingishing factors were a M- at the start of a file, or the date in brackets after the title. I then needed to crop all the text aroudn the movie title so that cover art program could recognise the movie.

    EG
    Beetlejuice (1988)_GO!_2010_08_28_20_25_00.dvr-ms
    M-The Rookie_7TWO_2010_08_27_14_24_40.dvr-ms

    This looked after the 1st type of file

    rename *)*.dvr-ms *).dvr-ms

    This looked after the second type of file

    for /f “tokens=1-3* delims=-_.” %%1 in (‘dir /b *.dvr-ms’) do (
    rename “%%1-%%2_%%3_%%4” “%%2.dvr-ms”
    )

    Now either type of file shows up as Almost Famous.dvr-ms

    It took me a day to get there, and I would still be going without this site. So a big thankyou. I hope these solutions may help someone else.

    • 0