in reply to Strange behaviour when using glob in if condition

# do nothing if the directory is not empty return if glob("$directory/*");

glob skips filenames beginning with a dot, try return if glob("$directory/{*,.*}");

Update: Actually, upon re-reading the question I think I misunderstood what you are trying to do. Update 2: Yep, see my other reply for the solution.