Skip to content

Instantly share code, notes, and snippets.

@andrefabbro
Created December 12, 2018 17:08
Show Gist options
  • Save andrefabbro/ba26ee14f07f56af4916e91cbc031b8c to your computer and use it in GitHub Desktop.
Save andrefabbro/ba26ee14f07f56af4916e91cbc031b8c to your computer and use it in GitHub Desktop.
Generate Document Library From Text File
#!/bin/bash
#
# Generate the Source file using: find -type f > filelist.txt
#
if [ $# -lt 1 ];
then
echo "Usage: $0 dl-filelist.txt [placeholder]"
else
IFS=$'\n'
FILELIST=$1
PLACEHOLDER='placeholder.jpg'
if [ $# -eq 2 ];
then
PLACEHOLDER=$2
fi
echo "Compiling file list..."
numFiles=`cat $FILELIST | wc -l`
currFile=0
skipFile=0
for i in `cat $FILELIST`;
do
if [ -e $i ] ;
then
((skipFile++))
else
echo -ne 'Copying file' $currFile 'of ' $numFiles '...\r'
mkdir -p `dirname $i`
cp $PLACEHOLDER $i
((currFile++))
fi
done
echo ""
echo "$numFiles total files."
echo "$currFile files copied."
echo "$skipFile files skipped."
echo "Done!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment