Checking if folder has files

前端 未结 6 1136
清歌不尽
清歌不尽 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:48

    I'm assuming (although I don't know for definite) that because you're calling GetFiles() on a network drive it adds considerable time to retrieve all the files from all 30k folders and enumerate through them.

    I've found an alternative Directory Enumerator here on CodeProject which looks promising.

    Alternatively... you could create a WebService on the server that enumerates everything for you and returns the results after.

    EDIT: I think your problem is more likely the folder access. Each time you access a Directory in the network drive you're going to be hitting security and permission checks. That * 30k folders will be a big performance hit. I highly doubt using the FindFirstFile will help much as the actual number of files enumerated will only ever be 0 or 1.

提交回复
热议问题