General Car Related Discussion. To discuss anything that is related to cars and automotive technology that doesnt naturally fit into another forum catagory.

Rename Dos command

Thread Tools
 
Search this Thread
 
Old 15-09-2004 | 03:25 PM
  #1  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default Rename Dos command

Can I rename a file in a Batch file to add a unique identifer on it

The orginal file Cricket_1.jpg Add either a % or a _ then a number upto what ever

So the renamed file is Cricket_1&23.jpg

Thanks lads
Old 15-09-2004 | 03:27 PM
  #2  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

I know you can use *1* but will at one to all the names not sequeal numbers
Old 15-09-2004 | 03:31 PM
  #3  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

you cannot automatically define the identifier (not easily anyway!)

you could use %1 tho

so say batch file is called johnny.bat

you'd say

c:\>johnny.bat 23

and your file would say:
IF %1 = "" ECHO TYPE SOMETHING YOU TWAT
REN CRICKET_1.JPG *%1.*

wich would create CRICKET_123.JPG
Old 15-09-2004 | 03:32 PM
  #4  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

to do sequential numbers you'd need NT scripting ideally.

you can do it in batch but you have to set upa control file and have the batch file read+update the control file... its properly complex and a right pain in the arse...

i struggled enough to add dates to filenames, and sequential numbers are even worse!!!!

do a search for batch programming in google, there are some really good websites with examples that helped me a lot... might find an easier method than the one i know of
Old 15-09-2004 | 03:35 PM
  #5  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

here's a thought... if its a batch file youre only ever gonna run once (ie you dont need it to remember which number it was on then run it again and it remembers) its a peice of piss... you just use the SET command to define a variable, then SET variable = variable +1 and keep using that variable in the file and call it with %variablename

example... type SET at the command prompt and you can see all the pre-defined variables like PATH and stuff...
Old 15-09-2004 | 03:41 PM
  #6  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

cheers Jim bob

If this did the time it would be good.


ren C:\DATA.txt DATA%dd%-%mm%-%yyyy%.txt

We have PA pictures comming comming in Say in the morning called cricket_1.jpg
the next would Cricket_2.jpg

Then in the afternoon different pictures come in with the same name and over right the pictures in the fooking database

say if a put the time in it may help
Old 15-09-2004 | 03:43 PM
  #7  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

Just read your last post Jim That may work
Old 15-09-2004 | 03:52 PM
  #8  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

johnny, does that %dd% %mm% %yy% thng work in 2k?

if so im gonna feel mighty silly... the program i had to do it was a BIT more complicated than that but it was what i was using on win95
Old 15-09-2004 | 03:54 PM
  #9  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

Code:
REM @echo off
echo.|date|find "Current" >cuXXent.bat
echo set date=%%5> current.bat
echo e 116 "-" > script
echo e 119 "-" >> script
echo w >> script
echo q >> script
type script | debug cu##ent.bat > nul
del script > nul
call cuXXent.bat
rem del cu??ent.bat >nul
Old 15-09-2004 | 03:56 PM
  #10  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

aye it does work in 2k

I did this in a .bat file

set pa=pa+1
rename *.jpg *%pa%.JPG

does not work

I think work in progress

tar
Old 15-09-2004 | 03:58 PM
  #11  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

aye that wont work

1st set pa to 1

then set a loop startpoint

then do an if exist to make sure theres a file there to rename (if not exist goto end)

then rename your file

then set pa to pa+1

then loop back to before the if exist

then just bung a :end in there
Old 15-09-2004 | 03:59 PM
  #12  
Jim Galbally's Avatar
Jim Galbally
20K+ Super Poster.
 
Joined: May 2003
Posts: 20,599
Likes: 0
From: Ramsgate, Kent Drives: E39 530D Touring
Default

you need the loop to run once for each individual file... you cant rename *.jpg to *%pa.jpg as itll try n call em all the same name (what PA is currently set to) and it wont update PA everytime

so command needs to run once, then update pa, then run again etc. etc. etc. untill you if exist command stops finding things existing and stops the batchfile running
Old 15-09-2004 | 04:01 PM
  #13  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

Me and dos bat are not friends

tar mate
Old 15-09-2004 | 04:02 PM
  #14  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

I see what you mean Jim bob

I think I need to think about this
Old 15-09-2004 | 04:03 PM
  #15  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

not as easy as first thought
Old 15-09-2004 | 04:08 PM
  #16  
vroooom ptssssh's Avatar
vroooom ptssssh
It Wasnt Me!
 
Joined: May 2003
Posts: 22,752
Likes: 8
From: Scottyland
Default

heres an example if u aint already done it?

To change the name of the file SALES.TXT on drive A to NEWSALES.TXT on drive A, enter

ren a:sales.txt newsales.txt

To change the filename extensions to TXT on all files on drive B that have SAL as the first three characters of the main filename, enter

ren b:sal*.* sal*.txt
Old 15-09-2004 | 04:09 PM
  #17  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

Wait a minute it does not matter that they are the same when they get first called

as the ones in the afternoon will be different
Old 15-09-2004 | 04:14 PM
  #18  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

tar vrooom
Old 15-09-2004 | 04:15 PM
  #19  
JohnnyB's Avatar
JohnnyB
Thread Starter
PassionFord Post Whore!!
 
Joined: May 2003
Posts: 8,594
Likes: 2
From: Derby
Default

fookit I will use Colur factory

Thanks for all your help
Old 15-09-2004 | 04:16 PM
  #20  
vroooom ptssssh's Avatar
vroooom ptssssh
It Wasnt Me!
 
Joined: May 2003
Posts: 22,752
Likes: 8
From: Scottyland
Default

Np
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
bobsworth
Restorations, Rebuilds & Projects.
77
24-03-2016 10:30 PM
abz474
Cars for Sale
9
01-11-2015 07:53 PM
A.t.p
Ford Escort RS Turbo
14
23-10-2015 08:54 PM
gingeRS
General Car Related Discussion.
17
02-10-2015 10:42 AM
rsguy
General Car Related Discussion.
44
29-09-2015 04:29 PM




All times are GMT. The time now is 07:38 PM.