diff --git a/src/filemanager/file.c b/src/filemanager/file.c index 17d64fe54..119ecf380 100644 --- a/src/filemanager/file.c +++ b/src/filemanager/file.c @@ -1484,19 +1484,21 @@ check_dir_is_empty (const vfs_path_t * vpath) { DIR *dir; struct vfs_dirent *d; - int i = 0; + int i = 1; dir = mc_opendir (vpath); if (dir == NULL) return -1; - /* https://stackoverflow.com/questions/6383584/check-if-a-directory-is-empty-using-c-on-linux */ - while ((d = mc_readdir (dir)) != NULL) - if (++i > 2) + for (d = mc_readdir (dir); d != NULL; d = mc_readdir (dir)) + if (!DIR_IS_DOT (d->d_name) && !DIR_IS_DOTDOT (d->d_name)) + { + i = 0; break; + } mc_closedir (dir); - return i <= 2 ? 1 : 0; + return i; } /* --------------------------------------------------------------------------------------------- */