From e84bc9896e9fd8f9d620d77539d252751898256f Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Thu, 12 Dec 2024 15:39:50 +0200 Subject: [PATCH] Skip empty dir --- fix_dir_dates.sh | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fix_dir_dates.sh b/fix_dir_dates.sh index 0e96c5a..51c0355 100755 --- a/fix_dir_dates.sh +++ b/fix_dir_dates.sh @@ -1,23 +1,25 @@ #!/bin/bash while read -r dir do - 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)" - fi - if [ "${last_file}" == "${dir}/" ]; then - echo "Skipping, no file found in dir" - else - echo "Last modified file is '${last_file}'" - filetime="$(jq '.info_dict.filetime' -- "${last_file}" )" - if [ "${filetime}" != "null" ] && [ -n "${filetime}" ]; then - last_file_time_formated=$(date -d "@${filetime}" +%Y%m%d%H%M.%S) - echo "Setting times for '${dir}' to '${last_file_time_formated}'..." - touch -t "${last_file_time_formated}" -- "${dir}" + 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)" + fi + if [ "${last_file}" == "${dir}/" ]; then + echo "Skipping, no file found in dir" else - echo "Setting times for '${dir}' to same as '${last_file}'..." - touch -r "${last_file}" -- "${dir}" + echo "Last modified file is '${last_file}'" + filetime="$(jq '.info_dict.filetime' -- "${last_file}" )" + if [ "${filetime}" != "null" ] && [ -n "${filetime}" ]; then + last_file_time_formated=$(date -d "@${filetime}" +%Y%m%d%H%M.%S) + echo "Setting times for '${dir}' to '${last_file_time_formated}'..." + touch -t "${last_file_time_formated}" -- "${dir}" + else + echo "Setting times for '${dir}' to same as '${last_file}'..." + touch -r "${last_file}" -- "${dir}" + fi fi fi done <<< "$(find . -mindepth 1 -maxdepth 1 -type d)"