Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
abo_fahad
- Posts: 3
- Joined: 23 Jan 2008 12:12
#1
Post
by abo_fahad » 23 Jan 2008 12:54
Hi,
i have unKnown number of images.jpg
i need MS DOS Batch file to Group them in One New file
and Rename them with new numbers i generate from Visual basic code.
i found out the VB code to run ms dos batch file passing parameters(witch
in this case will be the new numbers of images)
the VB code is:
Code: Select all
[b]Private Sub cmdRun_Click()
Shell App.Path & "\dosbatch.bat " & _
txtparameters.Text, vbNormalFocus
End Sub[/b]
but i need the MS DOS Batch file i mention before
can you help me pls.
thanks in advance.
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#2
Post
by jeb » 31 Jan 2008 03:24
Hi,
i have unKnown number of images.jpg
i need MS DOS Batch file to Group them in One New file
What are the names of the files and what to do with them?
My understanding of the behavior is:
The batch file collect all img*.jpg files and put them in to a list,
then the batch file starts to rename all filenames from the list to
myNewImg-1.jpg to myNewImg-n.jpg. The order of the files will be random(order of the collected filenames).
ex.
your files:
myPet.jpg
myCat.jpg
myDog.jpg
myDog2.jpg
after dosbatch.bat
myPet.jpg -> myImg1.jpg
myCat.jpg -> myImg2.jpg
myDog.jpg -> myImg3.jpg
myDog2.jpg -> myImg4.jpg
Is this your aim?
jeb
-
abo_fahad
- Posts: 3
- Joined: 23 Jan 2008 12:12
#3
Post
by abo_fahad » 31 Jan 2008 12:23
thanks for reply jeb
you are allmost right
actualy i recive these images from adf scanner(auto feeder)
with these names: image 001.jpg, image 002.jpg, image 003.jpg ... etc.
i need to give image 001.jpg the name master 001.jpg
and the rest of the files give them the name attach 001.jpg, attach 002.jpg
attach 003.jpg ... etc. and so on.
i hope i could Clarifie it to u.
thanks again
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#4
Post
by jeb » 01 Feb 2008 02:22
Hi Abo,
a solution with use of array lists.
Loads first the filenames in to an array
picList[0]=image001.jpg
picList[1]=image002.jpg
picList[2]=image003.jpg
then it replace the name with "master" or "attach".
Code: Select all
@echo off
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
dir /b /on image*.jpg > pictureList.tmp
call :loadFile picList pictureList.tmp
del pictureList.tmp
:: Iterate through the array and rename all files
set /a max=picList.length-1
for /L %%i in (0,1,%max%) do (
set srcName=!picList[%%i]!
if %%i==0 (
set dstName=!srcName:image=master!
set /a first=0
) ELSE (
set dstName=!srcName:image=attach!
)
echo ren !srcName! !dstName!
)
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::
:loadFile <resultVar> <filename>
:: loads a file <filename> into an array of <resulVar>[0] to <resulVar>[n] and set <resulVar>.length=n+1
:: WITHOUT setlocal, because it is else a bit complicated to use loadFile.counter
:: loadFile.counter will be set global, but i don't find a way to stop that
set /a loadFile.counter=0
for /f "tokens=*" %%a in (%~2) do (
set %~1[!loadFile.counter!]=%%a
set /a loadFile.counter=loadFile.counter+1
)
set %~1.length=%loadFile.counter%
goto :eof
bye
Jan Erik
-
abo_fahad
- Posts: 3
- Joined: 23 Jan 2008 12:12
#5
Post
by abo_fahad » 01 Feb 2008 07:26
thank u very mutch jeb
i am new on dos programming
i will try to understand the code and run it
thanks again jeb
-
jaffamuffin
- Posts: 40
- Joined: 25 Jan 2008 14:05
#6
Post
by jaffamuffin » 03 May 2008 15:49
Is there any limit on the number of files (images) that could be recorded into variables like this? In my tests I have found dropping about 31/32 files onto a batch and reading them in to array style like that is the limit...
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#7
Post
by jeb » 04 May 2008 14:09
Hi jaffamuffin,
I tested it now with 2644 files (Windows\System32), with no problems (only echo the filenames).
I'm using Vista yet, but on XP I use a similiar batch with more than 100 files.
Your break at 30 files seems to be another problem.
jeb
-
jaffamuffin
- Posts: 40
- Joined: 25 Jan 2008 14:05
#8
Post
by jaffamuffin » 05 May 2008 04:00
Interesting, I definately need to look at this.
I'm trying to write a batch file that will accept either, 1 image, more than one image (upto around a 1000) or a folder, dropped onto the icon.
Will post up some code later.
Cheers
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#9
Post
by jeb » 06 May 2008 05:44
Hi,
try this as an idea
Code: Select all
:::::::::::::::::::::::::::::::::::::::::::::::::
:loadFile <filename> <resultVar>
:: Loads the content of a file into an array an set the length of the array
:: without setlocal, because the array should be visible outside of this function
set loadFile.counter=0
for /f "tokens=*" %%a in (%1) do (
set %2[!loadFile.counter!]=%%a
set /a loadFile.counter=loadFile.counter+1
)
set %2.length=%loadFile.counter%
goto :eof
jeb