Question

What I want to accomplish is to rename all the .exe that I have in a folder.

Sample of random name should be "589uday5xpsa9iz.exe"

I would appreciate any help I can get on this, I have been trying to figure it out for a couple of days now.

Was it helpful?

Solution

Try this :

@echo off
setlocal enabledelayedexpansion

:://The string length of the output
set $Lcode=16
set $#=#

:://The char Map
set $l="#0=0" "#1=a" "#2=B" "#3=c" "#4=d" "#5=E" "#6=f" "#7=g" "#8=H" "#9=I" "#10=j" "#11=K" "#11=1" "#13=2" "#14=3" "#15=4" "#16=5"

:://Evaluating the char MAP
for %%a in (%$l%) do set %%~a

:://Looping in the directory for .exe files
for /f "delims=" %%x in ('dir /b/a-d "*.exe"') do (
    for /l %%a in (0,1,%$Lcode%) do (
    call:rand
    )
    ECHO ren "%%x" !$Fstring!.exe
    set $Fstring=
)
pause
exit/b

:://Getting the random Char
:rand
set /a $n=!random!%%17
set $Fstring=!$Fstring!!#%$n%!

I made a char MAP of just 15 char but you can increase it with all the char (up and downcase + number). If you do it. You have to increase the value in !random!%%17 with the value of the total CHAR map(+1).

You can increase the length of the random string by changing the value in the variable : $Lcode (16) in this example.

The output :

ren CnpjSdee.exe 2aHg5I22EBBE2ff5.exe
ren DbatchCnpj.exe EIIg2E54aHHIEgfHE.exe
ren NTStreamColor.exe jg03f3dIfBfIfHj2.exe
ren savedialog.exe EgfdajIcdc2cf03E.exe
Press any key to continue. . .

If it's OK Remove the ECHO to realy rename the files.

OTHER TIPS

this is a simple batch that will work from within the folder that contains the files to be renamed you could make a shortcut to use it from the desk top. use copy and paste for long names. C:\Documents and Settings\Owner\Desktop\New Folder\Rename.bat (file = Rename.bat) don't use the whole path.

@echo off
title Rename Bat
echo This bat must be in the folder that 
echo contains the files to be renamed.
:begin
echo Enter File Name
set /p old=
echo Enter New Name
set /p new=
ren "%old%" "%new%"
echo File Renamed
ping -n 3 127.0.0.1 >NUL
goto begin

hope this works for you.

a much simpler approach ... try a for loop that cycles through all files in that folder and renames them one at a time giving each a unique number ...

@echo off

for /L %%n in (1 1 %random%) do (

for %%a in (*.exe) do (

rename "%%a" "%%a_%%n.exe"


)

)

so %%a represents all the files in that folder and %%n represents the unique number that is going to be assigned to each file in the for body separated with _ symbol

to use this batch file you have to place it in the folder containing your .exe files

this would rename files to original name_1 then original name _2 and so on if you want it to be completely random use only %random% in bracket of the first for loop and do away with the iteration "1" (see below) also at the renaming part do away with %%a to omit the original name of file so that you remain with only random numbers also see below e.g

    @echo off

    for /L %%n in (%random%) do (

    for %%a in (*.exe) do (

    rename "%%a" "%%n.exe"


    )


)

hope this helps .....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top