Two scripts (for bash and cmd.exe) to automatically add an empty index.php to each web directory. Useful to prevent access to directory listings when web host does not support editing .htaccess.
Linux / OS X version: addindex.sh.gz - 500 bytes
Windows version: addindex.zip - 523 bytes
Cmd source:
@echo off
pushd .
setlocal

if {%1} == {} (
  SET TARGET=.
  SET WHERE=the current directory
) else (
  SET TARGET=%1
  SET WHERE=%1
)

echo This will add index.php to %WHERE% and subdirs, if index.php/html does not exist yet.
echo Press CTRL-C to STOP, ENTER to continue
pause

cd /d %TARGET%
if ERRORLEVEL 1 (
  echo Error, cannot cd to %TARGET%
  goto :doerr
)

for /R %%d in (.) do (
 cd %%d
  if not exist index.php  (
    if not exist index.html (
      echo adding %%d\index.php
      echo . >>index.php
    )
  )
)

endlocal
popd
exit /b 0
rem goto :EOF

:doerr
popd
endlocal 
exit /b 1
goto :EOF
Bash source:
#!/bin/bash

function chkAdd() {
        pushd . >/dev/null
        cd "$1"
        if [ $? -gt 0 ] ; then
                echo ERROR: cannot cd to $1
                exit
        fi
        if [ ! -f "index.php"  ]  && [ ! -f "index.html"  ]
        then
          echo adding `pwd`/index.php
          touch index.php
        fi
        for item in *
        do
                if [ -d "$item" ] ; then
                        chkAdd $item
                fi
        done  
        popd >/dev/null
}

if [ "$1" = "" ] ; then
        TARGET=.
        WHERE="the current directory"
else 
        TARGET="$1"
        WHERE="$1"
fi

STOP="Stop"
CONTINUE="Continue" 
echo "This script will check for the presence of index.php/html in" $WHERE " and all its subdirectories, adding (an empty) index.php, if it does not exist already."
select opt in $CONTINUE $STOP
do
    if [ "$opt" = $CONTINUE ]; then
                break
       elif [ "$opt" = $STOP ]; then
        echo Aborting
                exit
       else
        echo bad option
                exit
      fi
done

chkAdd "$TARGET"