'Add file name to txt file if it is not zero bytes

I would like to add files that meet a set of conditions to a txt file for easy transfer later, I do this with:

ls -1 > AllFilesPresent.txt

value=$(<AllFilesPresent.txt)

rm AllFilesPresent.txt

for val in $value; do
  case $val in
    (Result*.RData) echo "$val" >> CompletedJobs.txt ;;
  esac
done

I've run into the situation where some of the files are corrupted and show up as zero byte files, which i can find manually with:

find . -size 0 -maxdepth 1

How do I include adjust my loop to reject files that are zero bytes?



Solution 1:[1]

-s file True if file exists and has a size greater than zero.

ls -1 > AllFilesPresent.txt
value=$(<AllFilesPresent.txt)
rm AllFilesPresent.txt
for val in $value; do
  if [[ -s "${val}" ]]; then
    case $val in
      (Result*.RData) echo "$val" >> CompletedJobs.txt ;;
    esac
  fi
done

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rakesh Gupta