REM ## This file is everything I love about using batch files for quick desktop operations. This little script will:
REM 1- use the lesson folder names as a variable
REM 2- capitalize the first letter and strip underscores when using the folder name as a title
REM 3- grab the word lists from all of the lesson folders and use the first word as the Spanish variable, the second as the English variable on each line
REM 4- strip Spanish accent characters from words used for mp3 or image names
REM 5- write a unique slideshow.txt config file for each lesson
REM 6- begin each config file with a non looping slideshow lesson title section
REM 7- iterate through the word lists to create unique slides using the Spanish and English words as variables for words, images, and audio
REM 8- keep a count in order to correctly number each slide
REM 9- save each slideshow.txt to the /glossary folder of the appropriate lesson unit, for use in generating the actual slideshow. This can be done in batch as well...
REM I'd like to see somebody show me another way to do all of the above with 1 click on your desktop, without installing a bunch of tools that require me to run everything from the command line or another shell, or with less code than this. Really no point anyway, as this code just simply works.
REM By Stacey Tipton Reiman, www.akwebgenius.com/blog ##
@echo off
REM let's setlocal and enable delayed expansion since that's what DOS needs to see in order to work with the variables in the way we've laid out below!
setlocal ENABLEDELAYEDEXPANSION&pushd %~dp0
REM add our alphabets for upper and lower case...
set UCase=ABCDEFGHIJKLMNOPQRSTUVWXYZ
set LCase=abcdefghijklmnopqrstuvwxyz
REM let's make a loop that will create a variable for each folder/directory in the list we already made with a previous batch file [each name or variable is marked by a new line in this file, directory_list.txt]
for /f "tokens=1 delims=." %%n in (directory_list.txt) do (
set dirs=%%n
set uppercase_dirs=%%n
REM here is the code that capitalizes ONLY the first letter of each word to uppercase, and removes any dashes or underscores, for nice titles
echo here is my raw folder name: !dirs!
set myfirst=!dirs:~0,1!
for /L %%A in (0,1,25) do Call :ToUpper !LCase:~%%A,1! !UCase:~%%A,1!
set uppercase_dirs=!myfirst!!dirs:~1!
set uppercase_dirs=!uppercase_dirs:-= !
set uppercase_dirs=!uppercase_dirs:_= !
echo here is my newly upper case'd title: !uppercase_dirs!
pause
REM /end code that capitalizes first letter
set fileoutta=!dirs!/glossary/slideshow.txt
echo here is my folder/directory !dirs!
echo here is my file out !fileoutta!
pause
REM OK now let's begin writing our slideshow configuration file, anything in the following section will only be written once
echo @@ Section, Category, and Lesson Info @@ >> !fileoutta!
pause
echo _show-!dirs! >> !fileoutta!
echo _Kids >> !fileoutta!
echo _Week >> !fileoutta!
echo _!dirs! >> !fileoutta!
echo _!uppercase_dirs! >> !fileoutta!
echo _!dirs! >> !fileoutta!
echo _!uppercase_dirs! >> !fileoutta!
echo here is my directory/folder again !dirs!
REM /end of the "write only once" section at the top of each slideshow.txt
REM let's start a count, shall we? Start at 1
set /a Cnt=1
echo _@@ Slide !Cnt! [string, title, image, animation, audio] @@ >> !fileoutta!
echo _q6-0-0-blue-translation-!uppercase_dirs!-false >> !fileoutta!
echo _q1-0-300-blue-null-false >> !fileoutta!
echo _q7-null >> !fileoutta!
echo _q7-bubby!dirs!.swf-null-0-0-s1 >> !fileoutta!
echo _null >> !fileoutta!
REM OK now let's add a loop that will iterate through the word list, and create 2 slide types that will keep replicating until the glossary wordlist for that directory/folder is complete...
FOR /F "tokens=1,2 delims=_" %%A in (!dirs!/glossary/glossary.txt) do (
REM Let's keep adding to the count, adding another number for every REGULAR slide we produce
set /a Cnt+=1
REM let's set the Spanish word to the first variable, and the English word to the second [found in glossary.txt]
set spanish_word=%%A
set english_word=%%B
set spanish_word_no_accent=%%A
REM let's strip the spanish accents from words we are using for image or mp3 files...
set spanish_word_no_accent=!spanish_word_no_accent:é=e!
set spanish_word_no_accent=!spanish_word_no_accent:á=a!
set spanish_word_no_accent=!spanish_word_no_accent:í=i!
set spanish_word_no_accent=!spanish_word_no_accent:ó=o!
set spanish_word_no_accent=!spanish_word_no_accent:ú=u!
set spanish_word_no_accent=!spanish_word_no_accent:ñ=n!
set spanish_word_no_accent=!spanish_word_no_accent:¿=!
set spanish_word_no_accent=!spanish_word_no_accent:?=!
set spanish_word_no_accent=!spanish_word_no_accent:¡=!
echo _@@ Slide !Cnt! [string, title, image, animation, audio] @@ >> !fileoutta!
echo _q6-0-0-blue-!spanish_word!-!english_word!-false >> !fileoutta!
echo _q2-0-0-redbold-null-false >> !fileoutta!
echo _q7-!spanish_word_no_accent!.swf >> !fileoutta!
echo _q7-null-null-0-0-s1 >> !fileoutta!
echo _!spanish_word_no_accent!.mp3 >> !fileoutta!
REM Let's keep adding to the count, adding another number for every SCRAMBLE slide we produce
set /a Cnt+=1
echo _@@ Slide !Cnt! [string, title, image, animation, audio] @@ >> !fileoutta!
echo _q6-0-0-blue-null-%%B-false >> !fileoutta!
echo _q1-0-450-instruct-%%A-false >> !fileoutta!
echo _q10-!spanish_word_no_accent!.swf >> !fileoutta!
echo _q9-scramble.swf-null-0-0-s1 >> !fileoutta!
echo _!spanish_word_no_accent!.mp3 >> !fileoutta!
REM /end of the looping of the 2 slides in the slideshow.txt
REM end for loop
)
REM end !dirs! for loop
)
cls
endlocal
REM here is our function that performs the uppercase on the first letter of each word in our title
:ToUpper Low Up
set uppercase_dirs=!uppercase_dirs:-%1=-%2!
set uppercase_dirs=!uppercase_dirs:_%1=_%2!
set myfirst=!myfirst:%1=%2!