Directory listing SQL query fix