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

Author Topic: Increment number base on number in same folder  (Read 3179 times)

0 Members and 1 Guest are viewing this topic.

radema

    Topic Starter


    Starter

    • Experience: Beginner
    • OS: Windows 10
    Increment number base on number in same folder
    « on: March 02, 2018, 08:02:38 PM »
    Filenumber_Groupnumber_filename

    I would like to increment filenumber if a duplicate Groupnumber is found. Then restart the increment with other group number.

    For example:
    If I will save 1_filename it will renamed as 1_1_filename.
    If I will save 1_filename it will renamed as 2_1_filename.
    If I will save 2_filename it will renamed as 1_2_filename.
    If I will save 2_filename it will renamed as 2_2_filename.
    ....

    @echo off
    setlocal enabledelayedexpansion

    REM this will identify the biggest number
    set max=0
    for %%x in (*.*) do (
      set "FN=%%~nx"
      set FN=!FN:~2,1!
      if !FN! GTR !max! set max=!FN!
    )
    rename ....

    The code above will only work with only one group per folder. Would it be possible to change the script so that it can identify groupnumber from each other in same folder and then add an increment number differently from each groupnumber.


    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Increment number base on number in same folder
    « Reply #1 on: March 02, 2018, 08:11:06 PM »
    And the other problem with your code is that it will only handle single digit numbers. Use a FOR /F command instead to break up the file name I to three chunks by using the underscore as a delimiter.

    radema

      Topic Starter


      Starter

      • Experience: Beginner
      • OS: Windows 10
      Re: Increment number base on number in same folder
      « Reply #2 on: March 02, 2018, 11:32:19 PM »
      Thanks for pointing that out.