Solved

dos batch rename file extension

Posted on 2006-11-19
11
385 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:fmew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 10

Expert Comment

by:fostejo
ID: 17974530
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,
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 17974547
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
0
 
LVL 4

Expert Comment

by:Raymun
ID: 17974917
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:Raymun
ID: 17974963
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
0
 

Author Comment

by:fmew
ID: 17978269
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
0
 
LVL 4

Accepted Solution

by:
Raymun earned 500 total points
ID: 17980980
Of course! Try this:

@echo off
setlocal enabledelayedexpansion

cd Data

set count=0
set FolderCount=-1
set FolderName=Folder!FolderCount!
set NumFilesPerFolder=1000

for %%a in (*.*) do (
      if !count! lss 100000 set NewName=test.!count!
      if !count! lss 10000 set NewName=test.0!count!
      if !count! lss 1000 set NewName=test.00!count!
      if !count! lss 100 set NewName=test.000!count!
      if !count! lss 10 set NewName=test.0000!count!

      set /a Result=!count! %% !NumFilesPerFolder!

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

      move %%a !FolderName!\!NewName!

      set /a count=!count!+1
)

cd ..

endlocal
0
 

Author Comment

by:fmew
ID: 17985942
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
0
 

Author Comment

by:fmew
ID: 17986162
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
0
 

Author Comment

by:fmew
ID: 17986336
Wait,

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

Erik
0
 
LVL 4

Expert Comment

by:Raymun
ID: 17987791
Just a minor change.

Change:

move %%a !FolderName!\!NewName!

to

move %%a !FolderName!\%%a
0
 

Author Comment

by:fmew
ID: 17988012
Thx Raymun

This works fine for me

Erik
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Progress
Starting up a Project

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question