Skip empty dir

This commit is contained in:
Antonio J. Delgado 2024-12-12 15:39:50 +02:00
parent c38ace8ab7
commit e84bc9896e

View file

@ -1,23 +1,25 @@
#!/bin/bash #!/bin/bash
while read -r dir while read -r dir
do do
echo "Checking dir '${dir}'..." if [ -n "${dir}" ]; then
last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)" echo "Checking dir '${dir}'..."
if [ "${last_file}" == "${dir}/" ]; then last_file="${dir}/$(ls -ht -- "${dir}/" | grep \.webm\.download_info\.json | head -n1)"
last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)" if [ "${last_file}" == "${dir}/" ]; then
fi last_file="${dir}/$(ls -ht -- "${dir}/" | head -n1)"
if [ "${last_file}" == "${dir}/" ]; then fi
echo "Skipping, no file found in dir" if [ "${last_file}" == "${dir}/" ]; then
else echo "Skipping, no file found in 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 else
echo "Setting times for '${dir}' to same as '${last_file}'..." echo "Last modified file is '${last_file}'"
touch -r "${last_file}" -- "${dir}" 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
fi fi
done <<< "$(find . -mindepth 1 -maxdepth 1 -type d)" done <<< "$(find . -mindepth 1 -maxdepth 1 -type d)"