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

Author Topic: random rename help  (Read 3014 times)

0 Members and 1 Guest are viewing this topic.

dragonmaster2091

    Topic Starter


    Rookie

  • If God grows it, we can smoke it.
    random rename help
    « on: January 25, 2008, 08:06:31 PM »
    Ok, so I was trying to make a batch file to rename all pictures in a folder to a random number between 1 and 29, the only problem is, it'll only rename one picture and it says "A duplicate file name exists, or the file cannot be found. So I tried to do a loop code but it did the same thing, except it repeated that message over and over and over. Here is the code.

    @echo off
    set /A random=%random% %% 29
    set /A random=%random% + 1
    ren *.gif %random%.gif
    pause
    exit

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: random rename help
    « Reply #1 on: January 26, 2008, 05:50:22 AM »
    This example assumes the batch file is in the same folder as the pictures:

    Code: [Select]
    @echo off
    setlocal enabledelayedexpansion
    for /f  "tokens=* delims=" %%x in ('dir /b *.gif') do (
    set rnd=!random!
    set /A rnd=!rnd! %% 29
    set /A rnd=!rnd! + 1
    ren %%x !rnd!.gif
    )

    The duplicate file problem still exists. The random number generator does not keep track of previous numbers pulled. Not only is it possible to pull duplicate numbers, it's even more likely by limiting the pool to 29 numbers.

    From reading other posts, there seems to be a whole lot of fascination in random this week.   8)
    « Last Edit: January 26, 2008, 08:27:22 AM by Sidewinder »
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    WillyW



      Specialist
    • Thanked: 29
    • Experience: Experienced
    • OS: Windows XP
    Re: random rename help
    « Reply #2 on: January 26, 2008, 09:35:13 AM »
    Ok, so I was trying to make a batch file to rename all pictures in a folder to a random number ...

    Is renaming the goal here,   or is randomness via a batch file more important?

    For what it is worth:     Irfanview has a batch rename function.     It is a very nice program for handling pictures, etc.
    Irfanview is free.

    http://www.irfanview.com

    .



    dragonmaster2091

      Topic Starter


      Rookie

    • If God grows it, we can smoke it.
      Re: random rename help
      « Reply #3 on: January 27, 2008, 03:25:50 AM »
      Thanks Sidewinder, your solution did the trick to all but one picture, but then all I had to do was change one picture's name to the number that wasn't on there lol.

      qinghao



        Intermediate
      • Don't think your self special
        Re: random rename help
        « Reply #4 on: January 28, 2008, 08:14:29 AM »
        learning....
        ;D