Monitoring a directory for new file creation without FileSystemWatcher

前端 未结 8 541
臣服心动
臣服心动 2021-01-31 06:51

I have to create a Windows service which monitors a specified folder for new files and processes it and moves it to other location.

I started with using FileSyste

8条回答
  •  北海茫月
    2021-01-31 07:22

    You could use Directory.GetFiles():

    using System.IO;
    
    var fileList = new List();
    
    foreach (var file in Directory.GetFiles(@"c:\", "*", SearchOption.AllDirectories))
    {
        if (!fileList.Contains(file))
        {
            fileList.Add(file);
            //do something
        }
    }
    

    Note this only checks for new files not changed files, if you need that use FileInfo

提交回复
热议问题