Batchfile: simple slideshow with custom image order

Last week a friend of mine wanted to have a image slideshow for a presentation TV screen for an exhibition. Besides of a large number of images that should be displayed in order he wanted to display his company logo image every second image, like:

  1. image 1
  2. company image
  3. image 2
  4. company image
  5. image 3
  6. company image

I wanted to do this without writing a program or installing Perl (his laptop is a Windows box) so I did this with a tiny Windows batch file:

@ECHO OFF
setLocal EnableDelayedExpansion

SET count=1
SET IMAGEDIR=%1
SET FILLIMAGE=%2

cd %IMAGEDIR%
FOR %%a IN (*.*) DO ( call :do "%%a" )
GOTO :EOF

:do
SET UQ1=%1
ren %UQ1% "%count%_!UQ1:"=!"
set /a count+=1
copy %FILLIMAGE% "%count%.jpg"
set /a count+=1
GOTO :eof

Given the batchfile slideshow.bat, the directory with a copy of all the source images in C:images and the company logo image in C:companyimage.jpg the call simply is:

slideshow.bat "C:images" "C:companyimage.jpg"

This will rename all the pictures found in C:images with a number in front of the original file name – with one number left out; like 1,3,5,7,etc. The company image is copied in between all these images as 2.jpg, 4.jpg, 6.jpg, etc. Now simply viewing the first image with Windows Picture Viewer and hitting the slideshow button will display the files by name which is exactly the desired display order.

Regarding the batchfile: it would be possible to execute multiple statements within the DO ( … ) but that way the counter variable did not work. I had to do a call to a method which then changes the counter. Another issue was the unquoting of the file name. The “%%a” supplies the image file name with double quotes to the %1 inside the :do function. As the final name should be counter + image-name without unquoting it would look like 1_”my image.jpg” which will do an error. The magick is the !VAR:”=! which unquotes the string in VAR.