Link to home
Start Free TrialLog in
Avatar of fmew
fmewFlag for Netherlands

asked on

dos batch rename file extension

Hi There,

In a .cmd file I want to rename all file extensions in an incrementing way.
Like ren test.jpg test.00001, ren  test1.jpg test.00002 etc
I have less then 100.000 files, so it has to start with 5 digits

Erik
Avatar of fostejo
fostejo

fmew,

Rather than a cmd file or script (which will, of neccessity, have very limited functionality), it may be worthwhile having a look at a generic file renaming tool like Batch File Renamer (http://www.1000files.com/Utilities/File_and_Disk_Management/Batch_File_Utility_8594_Review.html) - this allows you to play around with the renaming rules and preview the results prior to actually making any changes to the file names..

Obviously, it it *has* to be a script, let us know !

cheers,
for me could be easier to write an execitale for this task or use ACDSEE, XnView, Irfan view
here i found somedesciption
http://graphicssoft.about.com/cs/renamers/ht/renamexp.htm
Hey fmew,

Try this:

@echo off
setlocal enabledelayedexpansion

set count=0

:: Dont run in same directory as this batch!!
cd Data

for %%a in (*.*) do (
      set OldName=%%a
      set OldName=!OldName:~0,-3!
      
      if !count! lss 100000 set NewName=!OldName!!count!
      if !count! lss 10000 set NewName=!OldName!0!count!
      if !count! lss 1000 set NewName=!OldName!00!count!
      if !count! lss 100 set NewName=!OldName!000!count!
      if !count! lss 10 set NewName=!OldName!0000!count!

      if not exist !NewName! ren %%a !NewName!

      set /a count=!count!+1
)

cd ..

endlocal
I just re-read your question. I overlooked you not wanting to keep the file name. Try the following:

@echo off
setlocal enabledelayedexpansion

set count=0

cd Data

for %%a in (*.*) do (
      if !count! lss 100000 set NewName=test!count!
      if !count! lss 10000 set NewName=test0!count!
      if !count! lss 1000 set NewName=test00!count!
      if !count! lss 100 set NewName=test000!count!
      if !count! lss 10 set NewName=test0000!count!

      if not exist !NewName! ren %%a !NewName!

      set /a count=!count!+1
)

cd ..

endlocal
Avatar of fmew

ASKER

Great Raymun,

I just had to change test!count! to *.!count!  course I just need the extension to change.
What I want to do now is move and split the files i have (say *.00001 to *.20000) into different dirs with a maximum of say 1000 files in each dir.

I think now that maybe this can be done in once by just counting the files and move them to different dirs.

So (and I want to grade you dubble), do you know one way or the other to do this?

tnx Erik
ASKER CERTIFIED SOLUTION
Avatar of Raymun
Raymun

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fmew

ASKER

Hi Raymun,

Great again.
Now that the files are moved to different dirs, the extensions dont have to be a number.
In fact, I need them all to become <OrignalFileName>.jpg

I tried myself, but I do not succeed

Erik
Avatar of fmew

ASKER

Hi Raymun,

I tried again, and it works now. I did this:
@echo off
setlocal enabledelayedexpansion

cd\
cd abc

ren *.* *.jpg
set count=0
set ext="jpg"
set FolderCount=-1
set FolderName=Plaatjes!FolderCount!
set NumFilesPerFolder=300

for %%a in (*.*) do (
         
          set /a Result=!count! %% !NumFilesPerFolder!

     if !Result!==0 (
          set /a FolderCount=!FolderCount!+1
          set FolderName=Plaatjes!FolderCount!
          mkdir !FolderName!

    )
     
     move %%a !FolderName!\!NewName!

     set /a count=!count!+1
)

cd ..

endlocal

Thx Erik
Avatar of fmew

ASKER

Wait,

I did something wrong.
It only renames to jpg
So I still need an answer Raymon

Erik
Just a minor change.

Change:

move %%a !FolderName!\!NewName!

to

move %%a !FolderName!\%%a
Avatar of fmew

ASKER

Thx Raymun

This works fine for me

Erik