private void ProcessFiles()

in src/WebJobs.Extensions/Extensions/Files/Listener/FileListener.cs [254:292]


        private void ProcessFiles()
        {
            // scan for any files that require processing (either new unprocessed files,
            // or files that have failed previous processing)
            string[] filesToProcess = Directory.GetFiles(_watchPath, _attribute.Filter)
                .Where(p => _processor.ShouldProcessFile(p)).ToArray();

            if (filesToProcess.Length > 0)
            {
                _logger.LogDebug($"Found {filesToProcess.Length} file(s) at path '{_watchPath}' for ready processing");
            }

            foreach (string fileToProcess in filesToProcess)
            {
                WatcherChangeTypes changeType = WatcherChangeTypes.Created;
                string statusFilePath = _processor.GetStatusFile(fileToProcess);

                try
                {
                    StatusFileEntry statusEntry = null;
                    if (_processor.GetLastStatus(statusFilePath, out statusEntry))
                    {
                        // if an in progress status file exists, we determine the ChangeType
                        // from the last entry (incomplete) in the file
                        changeType = statusEntry.ChangeType;
                    }
                }
                catch (IOException)
                {
                    // if we get an exception reading the status file, it's
                    // likely because someone started processing and has it locked
                    continue;
                }

                string fileName = Path.GetFileName(fileToProcess);
                FileSystemEventArgs args = new FileSystemEventArgs(changeType, _watchPath, fileName);
                _workQueue.Post(args);
            }
        }