I use below code to find the oldest file in the directory:

find /Volumes/Hams\ Hall\ Workspace/Tabletop\ 7_WIP -type f ! -name '.DS_Store' ! -name '.uid' ! -name 'Thumbs.db' \( ! -regex '.*/\..*' \) -print0 | xargs -0 ls -lUr | head -n 1 >> ~/Desktop/test.csv 

It works most of the time. Although, if directory is empty and has custom Icon, it indexes the Icon, and outputs as if it is the oldest file. Although, if the directory is not empty, it will work as normal.

How would you go on skipping the Icon ? Or if the folder is empty, simply skip it entirely?

I've tried excluding it with:

  1. ! -name 'Icon'
  2. -not -path dir
  3. -type d \( ! -name dir \)
  4. -mindepth 1 -maxdepth 1
  5. Tried to find out if Icon is file or directory with both -f and -d. Both output that Icon doesn't exist. Yet the Icon still shows up in the log.

    if [[ -f /Volumes/Hams\ Hall\ Workspace/Tabletop\ 7_WIP/Icon ]] then echo the file exists > ~/Desktop/xxx.csv else echo the file does not exist >> ~/Desktop/xxx.csv fi

Either I am havig somewhere a syntax error, or something goes wrong after find, as none of the above worked.

enter image description here

Any help would be much appreciated.

0 Answers