Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help needed on renaming filenames with .bat  (Read 3817 times)

0 Members and 1 Guest are viewing this topic.

hayman

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows XP
    Help needed on renaming filenames with .bat
    « on: December 15, 2013, 09:33:31 AM »
    Hello forum users,

    First of all, my English isn't perfect; sorry for that. I like to do some editing on the PC-games I play. Now I kind of have an issue which needs your help.

    I have a map with files named like this:  head_1234_0.rx3 There a around 1500 of them, the numbers are all different and linked to a database. These are original files.
    I also have one head_x_bump.rx3 were the x should be corresponding to the 1234. I need all 1500 files to have a corresponding head_x_bump file. I can do this manualy, but that's too much work. That's why I created a bat file with the following code:
    Code: [Select]
    echo Enter number
    set /p number=
    copy head_x_bump.rx3 head_%number%_bump.rx3

    It works, but it's still a lot of work. I thougt that maybe it's possible to create a bat file wich "reads" the file names of the orriginal files.
    I have no idea how to do this.

    So is it possible to link the "1234" in the orginial filename to a copied en renamed head_x_bump file?



    Lemonilla



      Apprentice

    • "Too sweet"
    • Thanked: 70
    • Computer: Specs
    • Experience: Experienced
    • OS: Windows 7
    Re: Help needed on renaming filenames with .bat
    « Reply #1 on: December 15, 2013, 11:43:30 AM »
    so basicly you have 1 copy of a file named "head_x_bump.rx3" and you need to make a bunch of copies of it replacing x with a number?

    Code: [Select]
    @echo off
    set end=####

    for /l %%A in (1,1,%end%) do copy "head_x_bump.rx3" "head_%%A_0.rx3" && echo Copied number %%A.

    echo . . . Done
    pause>nul

    Or you have a bunch of "head_####_bump.rx3 and need a corresponding head_####_0.rx3 file for each,

    Code: [Select]
    @echo off
    end=####

    for /l %%A in (1,1,%end%) do copy "head_%%A_bump.rx3" "head_%%A_0.rx3" && echo Copied number %%A.
    echo . . . Done
    pause>nul



    Where end equals the total number of files (assuming there are no skips in numbers).
    Quote from: patio
    God Bless the DOS Helpers...
    Quote
    If it compiles, send the files.

    Salmon Trout

    • Guest
    Re: Help needed on renaming filenames with .bat
    « Reply #2 on: December 15, 2013, 12:05:36 PM »
    Lemonilla, you want the 2nd line of your 2nd script to be

    SET end=####

    hayman

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows XP
      Re: Help needed on renaming filenames with .bat
      « Reply #3 on: December 15, 2013, 01:14:15 PM »
      so basicly you have 1 copy of a file named "head_x_bump.rx3" and you need to make a bunch of copies of it replacing x with a number?

      Exactly!I added a picture to as example.



      I have around 1500 head_x_0.rx3 files that need a corresponding head_x_bump.rx3  (of which
      I have one version that I need to copy with corresponding numbers). For exaple the head_260084_bump.rx3 is what I need to create. Problem is -as you can see- the numbers do skip.

      So basicly I'm looking to make a copy of the head_x_bump and get the numbers from the head_260074_0.rx3 in the name of bump file at the position of the x


      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Help needed on renaming filenames with .bat
      « Reply #4 on: December 15, 2013, 06:02:46 PM »
      This creates the extra files, using the numbers from the existing files.

      Code: [Select]
      @echo off
      for /f "tokens=2 delims=_" %%a in ('dir head_*_0.rx3 /b /a-d ') do type nul >"head_%%a_bump.rx3"

      hayman

        Topic Starter


        Starter

        • Experience: Beginner
        • OS: Windows XP
        Re: Help needed on renaming filenames with .bat
        « Reply #5 on: December 16, 2013, 12:32:27 AM »
        Wauw, thnx!! It looks like it creates the files, but doesn't copy the original head_x_bump file. almost there ;)

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: Help needed on renaming filenames with .bat
        « Reply #6 on: December 16, 2013, 03:54:21 AM »
        My mistake - but it's a simple change. 

        Code: [Select]
        @echo off
        for /f "tokens=2 delims=_" %%a in ('dir head_*_0.rx3 /b /a-d ') do copy  "head_x_bump.rx3" "head_%%a_bump.rx3" >nul

        hayman

          Topic Starter


          Starter

          • Experience: Beginner
          • OS: Windows XP
          Re: Help needed on renaming filenames with .bat
          « Reply #7 on: December 16, 2013, 04:48:53 AM »
          I tried the same, but now I see I added an unnecessary >

           ;D Thnx a lot, it works!