Last active
December 5, 2017 21:25
-
-
Save hzg/98ebc770ebd48d64a15bd93e95c9a8d6 to your computer and use it in GitHub Desktop.
Bash script that will convert legacy vbulletin attachment directory structure from ./1234/xxxx.attach to ./1/2/3/4/xxxx.attach in order to import into xenforo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "vb4 Attachment Folder Structure Splitter" | |
# CHANGE THIS YOUR DESIRED COPY LOCATION | |
DEST="../dest" | |
for i in $(ls -d */); do | |
OLDDIR=${i%%/} #Set old director var | |
COUNT=${#OLDDIR} #Get Number of Directories | |
TOTAL=$((COUNT + 1)) #Set the total to plus 1 | |
COUNTER=1 #Set Counter | |
PATHBUILD="" #Path Builder Var | |
################################################### | |
#BUILD NEW FOLDERS FROM OLD | |
while [ $COUNTER -lt $TOTAL ]; do | |
FNAME=`expr substr $OLDDIR $COUNTER 1` | |
#PATH BUILD ex: 8/8/8/999.attach | |
PATHBUILD="$PATHBUILD/$FNAME" | |
COUNTER=$((COUNTER + 1)) | |
done | |
################################################### | |
#CREATE DESTINATION PATH | |
DESTPATH=$DEST$PATHBUILD | |
echo "creating: " $DESTPATH | |
mkdir -p $DEST$PATHBUILD | |
################################################### | |
#MOVE FILES | |
for ATTACHMENTS in `ls $OLDDIR`; do | |
OLDATTACH="$OLDDIR/$ATTACHMENTS" | |
ATTACHMOVE="$DESTPATH/$ATTACHMENTS" | |
echo $OLDATTACH " to " $ATTACHMOVE | |
cp $OLDATTACH $ATTACHMOVE | |
done | |
################################################### | |
done | |
echo "Finshed" | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment