From f71dac44dda7a9f11f1ad13ab07337e3bfae7190 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 14 Dec 2024 15:29:43 +0200 Subject: [PATCH] Use find to find last file --- fix_dir_dates.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fix_dir_dates.sh b/fix_dir_dates.sh index 219fb3d..3976621 100755 --- a/fix_dir_dates.sh +++ b/fix_dir_dates.sh @@ -3,11 +3,11 @@ while read -r dir do if [ -n "${dir}" ]; then echo "Checking dir '${dir}'..." - last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)" - if [ "${last_file}" == "${dir}/" ]; then - last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)" + last_file="$(find "${dir}/" -type f -printf "%T@ %p\n" | sort -n | grep \.webm\.download_info\.json | head -n1 | sed 's/^[0-9\.]* //')" + if [ "${last_file}" == "${dir}/" ] || [ -z "${last_file}" ]; then + last_file="$(find "${dir}/" -type f -printf "%T@ %p\n" | sort -n | head -n1 | sed 's/^[0-9\.]* //')" fi - if [ "${last_file}" == "${dir}/" ]; then + if [ "${last_file}" == "${dir}/" ] || [ -z "${last_file}" ]; then echo "Skipping, no file found in dir" else echo "Last modified file is '${last_file}'"