I have folders with the naming convention:
yearmonthday_jobcode_descriptor
ie 20101007_GR1234_Whatsit
I'm attempting to write a script that does a few things:
- move any folders where the date is older than $X into ./old
- move any folders where the date is in the future ./old
- move any folders that dont conform to the convention ./old
- delete any folders in ./old where the date is older than $X + $Y
Here is my current loop, as you can see my bash scripting is pretty mediocre.
#!/bin/bash
for file in $1/*; do
if [ -d $file ]; then
echo $(echo $file | grep -oE "[0-9]{8}_[A-Z]*[0-9]*_?.*")
fi
done
I can handle all the looping, my main concern at the moment is how to extract the folder names into variables that can be compared for dates. The current regex above just checks for conformity to the convention.