Skip to content

Instantly share code, notes, and snippets.

@FlaviuSim
Created April 5, 2011 04:05
Show Gist options
  • Save FlaviuSim/903001 to your computer and use it in GitHub Desktop.
Save FlaviuSim/903001 to your computer and use it in GitHub Desktop.
bash script to convert directory structure to xml - by @sente
function indent() {
depth=$1
spacer=${2:" "}
for ((i=0;i<$depth;i++)); do
echo -ne " ";
done
}
function recurse() {
local name=$1
local depth=${2:-0}
local i=$(indent $depth)
test -f $name && tag="file"
test -d $name && tag="dir"
echo -ne "\n$i<$tag>$(basename "$name")"
local childcount=0
for f in "$name"/*; do
if [ ! -d "$f" ]; then continue; fi
((childcount++))
local newdepth=$((depth+1))
recurse "$f" $newdepth
done
if [ $childcount -eq 0 ];
then echo -en "</$tag>"
else echo -ne "\n$i</$tag>"
fi
}
recurse $@
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment