batch file to renumber files in folders

January 7, 2010 at 14:21:54
Specs: Windows XP Home, AMD3800/2gb
I have a main folder (H:\videos) with many subfolders. These subfolders each have a bunch of videos with a name preceeded by a 4 digit number. For example:

0179 videoname.avi
0257 videoname.avi
1033 videoname.avi
etc

I need to delete the 4 digit numbers in each folder and renumber the files with a 2 digit number starting with 01.

This is way beyond my capabilities, so any help would really be appreciated.

(edit) Sorry! I tried to put this post in the Programming forum, but for some unknown reason, it ended up here.


See More: batch file to renumber files in folders

Report •


#1
January 7, 2010 at 14:43:12
There is a free fully functional program at http://www.snapfiles.com/get/bfrena...

This is a template, make changes as needed

cls
@echo off
echo Program should be same dir as jps

set n=1
for %%i in (*.jpg) do (
call ren %%i %%n%%.jp_
set /a n=n+1)
ren *.jp_ *.jpg


Report •

#2
January 7, 2010 at 15:57:33
@echo off & setLocal EnableDELAYedeXpansion

pushd H:\videos

set N=

for /f "tokens=* delims= " %%a in ('dir/b/s') do (
set /a N+=1
if !N! lss 10 (
set NUM=0!N!
) else (
set NUM=!N!
)
set NAME=%%~Na
set NAME=!NAME:~4,77!
ren "%%a" "!NUM!!NAME!%%~Xa"
)


=====================================
Helping others achieve escape felicity

M2


Report •

#3
January 8, 2010 at 10:16:55
Sorry I'm so late to responding. I ran into some system problems.

Thanks for your suggestions worldlibrary. but they seem to be for one folder, and I need to do many folders. I also got a syntax error on the 'set /a n=n+1'. But thanks very much anyway.

Thanks very much Mechanix2Go. Maybe I didn't explain my problem clearly. Your suggestion suggestion deleted the first part of the subfolders names and inserted the 2 digit sequence in the subfolders name. I need the files within the subfolders renamed.

I did the test on a small sample on a different drive, so there was no damage done.


Report •

Related Solutions

#4
January 8, 2010 at 11:02:13
I wrote it for AVIs in H:\videos.

I'll work it over.


=====================================
Helping others achieve escape felicity

M2


Report •

#5
January 8, 2010 at 19:51:13
Thanks Mechanix, there's no rush.

Report •

#6
January 9, 2010 at 01:06:42
Sorry,

I'm lost.

Please start a new thread.


=====================================
Helping others achieve escape felicity

M2


Report •

#7
January 9, 2010 at 09:38:39
I'm sorry that I can't explain the problem very well. Thanks Mechanix,. but I think I will just keep on doing it the old way, one folder at a time. It's time consuming, but I have plenty of that.

Thanks very much anyway!


Report •

Ask Question