Checking if folder has files

前端 未结 6 1122
清歌不尽
清歌不尽 2021-02-10 09:58

I have program which writes to database which folders are full or empty. Now I\'m using

bool hasFiles=false;
(Directory.GetFiles(path).Length >0) ? hasFiles=         


        
6条回答
  •  爱一瞬间的悲伤
    2021-02-10 10:30

    To check if any files exists inside the directory or sub directories, in .net 4, you can use method below:

    public bool isDirectoryContainFiles(string path) {
        if (!Directory.Exists(path)) return false;
        return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories).Any();
    }
    

提交回复
热议问题