Checking files exist in a folder

I have some code that removes all files from a folder using rm in an execute shell script. But this breaks my macro if there are no files in the folder in the first place. Therefore, I want to check if any files exist in myFolder first and only run the rm code if there are files there.

Any ideas on how to do this?



If you pass rm the -f flag, then it will not error, would that be sufficient?

Alternatively, just use touch to create a bogus file, and then do your rm so you know a file will exist first.

Alternatively, you can check if a file exists in the folder with something like:

  • Set variable “Files Exist” to 0
  • For Each variable Path in contents of folder “whatever”
    • Set variable “Files Exist” to 1
    • Break From Loop

Ooo, yes if it doesn’t error that’s fine. I was getting a popup message box showing an error. I will try to add the flag, thank you. :smile: