From f511f165ede1f2ce9101f46ba8637a994d14262f Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Wed, 20 Nov 2024 12:47:30 +0200 Subject: [PATCH] option if no time or no file --- fix_dir_dates.sh | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/fix_dir_dates.sh b/fix_dir_dates.sh index de6b510..f5c281b 100755 --- a/fix_dir_dates.sh +++ b/fix_dir_dates.sh @@ -3,10 +3,19 @@ while read -r dir do echo "Checking dir '${dir}'..." last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)" - echo "Last modified file is '${last_file}'" - filetime="$(jq '.info_dict.filetime' -- "${last_file}" )" - if [ "${filetime}" != "null" ]; then - last_file_time_formated=$(date -d "@${filetime}" +%Y%m%d%H%M.%S) - touch -t "${last_file_time_formated}" -- "${dir}" + if [ -z "${last_file}" ]; then + last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)" + fi + if [ -n "${last_file}" ]; then + echo "Last modified file is '${last_file}'" + filetime="$(jq '.info_dict.filetime' -- "${last_file}" )" + if [ "${filetime}" != "null" ]; then + last_file_time_formated=$(date -d "@${filetime}" +%Y%m%d%H%M.%S) + touch -t "${last_file_time_formated}" -- "${dir}" + else + touch -r "${last_file}" -- "${dir}" + fi + else + echo "Skipping, no file found in dir" fi done <<< "$(find . -mindepth 1 -maxdepth 1 -type d)"