A difficult task

June 29, 2010 at 03:57:12
Specs: Windows Vista

I'm looking for a batch file to copy all .jpg files
from a selected
folder, copy those jpg's to another folder,
rename them and
then for the file that just had all those images
copied into,
zipped or compressed.

Let me go into a bit more detail. The image
directory looks like


I want to be able to run one batch file to copy
all .jpg's from
Clientimages and any sub folders inside of it,
but not the
folders themselves, just the images. Once all
the images have
been copied into this new file, I need them to
be renamed (or
they can be renamed while copying) into
names with numbers.
Here's an example:

Original - Clientname-Address.jpg
New - 24124242.jpg

So as you can see, what the new image name
is called
doesn't really matter, as long as it only
contains numbers.

From there I want the bat script to zip (or any
compression extension) the folder with the
new images and
then delete the newly created folder. From
there I'll move the
files off and send them to our clients.

I spent a few hours trying to make one batch
file to do this but I
didn't get very far. I figured out how to copy
them COPY

This copied everything within the Clientimages,
including the
folders, .txt documents and more.

Can anyone help me with this? :)

See More: A difficult task

Report •

June 29, 2010 at 12:14:32
OK, this is not quite complete - you need to add some sort
of zip command depending on what you choose to use (see
lines that begin with REM for more info...):

@echo off

setLocal EnableDelayedExpansion

set SrcFolder=C:\Users\Mathew\Clientimages\
set DestFolder=C:\Users\Mathew\Clientimages\ClientBackup\

if not exist "%DestFolder%" md "%DestFolder%"
for /f "delims=" %%f in ('dir /s /b "%SrcFolder%*.jpg"') do (
  call :GetNewFileName "%DestFolder%" newfile
  copy "%%f" "%DestFolder%!newfile!"
REM Add zip command here. The output needs to be to another
REM folder because %DestFolder% is about to be nuked !!
rd /s /q "%DestFolder%"
goto :eof

:GetNewFileName (destfolder_byval, newfile_byref)
set num=0
set /a num+=1
if exist "%~1%num%.jpg" goto loop
set %2=%num%.jpg
goto :eof

Report •
Related Solutions

Ask Question