.

batch file help

<<

O_o

Newbie
Newbie

Posts: 28

Joined: Fri Jul 22, 2011 12:57 pm

Post Wed Dec 28, 2011 10:48 am

batch file help

I need to make a batch file that will automaticly renamed files to numbers.
???
If your computer speaks English, than it was probably made in Japan.
<<

Ignatius

Jr. Member
Jr. Member

Posts: 91

Joined: Sun Mar 22, 2009 9:51 am

Post Wed Dec 28, 2011 1:41 pm

Re: batch file help

I'm not saying that I will necessarily be able to help, but can you give examples of how you need to have them renamed, i.e. maybe:

one.txt -----> 1.txt
two.txt ------> 2.txt
three.txt ----> 3.txt
four.txt -----> 4.txt

or

jpvf.doc ------------> 1
wioeprt.rtf ----------> 2
wdopemxs.jpg -----> 3
qwerty.wmv --------> 4

etc.
<<

hayabusa

User avatar

Hero Member
Hero Member

Posts: 1661

Joined: Mon Jan 29, 2007 2:59 pm

Post Wed Dec 28, 2011 2:44 pm

Re: batch file help

You could write something like the following:

rename.bat

set /a j=0

setlocal ENABLEDELAYEDEXPANSION

for /f %%a IN ('dir /b *.*') do (

set /a j=j+1

rename %%a !j!%%~xa

)


Edit:  The %%~xa preserves the file extension. Note, if you don't MOVE the resulting file to somewhere else, such as don't use rename but instead

copy %%a <some directory>/!j!%%~xa

it'll try to catch the renamed files, too...  So I'd use the copy and a temp dir, instead, perhaps creating the temp dir at the beginning of the batch file...
Last edited by hayabusa on Wed Dec 28, 2011 2:48 pm, edited 1 time in total.
~ hayabusa ~ 

"All men can see these tactics whereby I conquer, but what none can see is the strategy out of which victory is evolved." - Sun Tzu, 'The Art of War'


OSCE, OSCP , GPEN, C|EH
<<

O_o

Newbie
Newbie

Posts: 28

Joined: Fri Jul 22, 2011 12:57 pm

Post Thu Apr 19, 2012 4:29 pm

Re: batch file help

Thanx Mr.Hayabusa
If your computer speaks English, than it was probably made in Japan.

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron
.
Powered by phpBB® Forum Software © phpBB Group.
Designed by ST Software