Artificial intelligent assistant

Delete the oldest folder from a path with an exclusion I referred the following thread How to delete the oldest directory in a given directory? and the accepted solution is perfect. However, I have a requirement to exempt one folder that is the oldest. How I can accommodate this requirement within the solution provided?

You can adapt the original solution to read files until it finds one that is not excluded:


while IFS= read -r -d '' line
do
file="${line#* }"
if [ "$file" = './my-excluded-directory' ]
then
continue
fi
[do stuff with $file]
break
done < <(find . -maxdepth 1 -type d -printf '%T@ %p\0' | sort -z -n)


(`-d ''` is equivalent to the original, because you can't have NUL characters in strings.)

`read`ing a long list is slow though, and @mosvy is right that you can do the filtering with some rather nasty `find` syntax:


IFS= read -r -d '' < <(find . -maxdepth 1 -type d \( -name 'my-excluded-directory' -prune -false \) -o -printf '%T@ %p\0' | sort -z -n)
file="${REPLY#* }"
# do something with $file here

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy e232502e63e5db8cd191411e3590ef48