Windows Shell Scripts

I recently had to update my workspace that I use to keep track of jobs.  I have a job folder (“300”) and three sub-folders (“input, output, working”).  To create a new set of folders I use a batch file:

FOR /L %%G IN (300,1,599) DO (
echo Making job folder %%G...
mkdir %%G
echo Making input folder %%G...
mkdir %%G\input
echo Making output folder %%G...
mkdir %%G\output
echo Making working folder %%G...
mkdir %%G\working
)

This starts 300 and steps through the numbers to 599, incrementing by 1 each time and making the required folders.For processing raster images into an optimised format for use in GeoServer I use a similar batch file that calls multiple commands in each loop through the TIF images in a directory:

rem All in a wunner
 FOR /F %%G IN ('dir /b BG\*.tif') DO (
 echo EXPANDING %%G...
 gdal_translate -of Gtiff -a_srs EPSG:27700 -co "TILED=YES" -expand rgb BG\%%G BG_rgb\%%G
 echo OPTIMISING %%G...
 gdal_translate -of Gtiff -a_srs EPSG:27700 -co "TILED=YES" -co "TFW=YES" -co "PROFILE=Geotiff" -co "INTERLEAVE=PIXEL" -co "PHOTOMETRIC=YCBCR" -co "COMPRESS=JPEG" -co "JPEG_QUALITY=95" BG_rgb\%%G BG_opt\%%G
 echo DELETING UNCOMPRESSED TIFF %%G...
 del BG_rgb\*.tif
 echo ADDING OVERVIEWS TO %%G...
 gdaladdo -r gauss --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW YCBCR --config INTERLEAVE_OVERVIEW PIXEL BG_opt\%%G 2 4 8 16 32 64 128 256
 )

Leave a Reply

Your email address will not be published. Required fields are marked *