I have a bunch of files that were exported (from my trac wiki) that are named like ParentPage%2FSubPage
but they actually should be like ParentPage/SubPage
. Anyone have a quick and dirty way to rename and organize them, so that ParentPage
will be a directory, and then SubPage
will be a file inside that?
Slightly modified from @Christopher Karel's answer, which is what I used:
for FILE in $(ls | grep "%2F")
do
CONVERTED=$(echo $FILE | sed -e 's/%2F/\//g')
DIRNAME=$(dirname $CONVERTED)
if [ -f $DIRNAME ]; then mv $DIRNAME $DIRNAME.page; fi
mkdir -p $DIRNAME
if [ -f $DIRNAME.page ]; then mv $DIRNAME.page $DIRNAME/$(basename $DIRNAME); fi
mv $FILE $CONVERTED
done
and the test data I used (in an empty dir), before running the above:
touch Test; touch Test%2FA%2F1; touch Test%2FA%2F2; touch Test%2FB
OK, here's a bash method to do this. Not foolproof, but quick and dirty.