Suppose someone copies files to the server in the place "B" from outside by some file manager.
How to understand if the file in the "B" place is completely copied and if so start processing it?
Suppose someone copies files to the server in the place "B" from outside by some file manager.
How to understand if the file in the "B" place is completely copied and if so start processing it?
The code is working, checked by downloading the Debian OS image via wget:
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace BusyFileObserver { class Program { private static bool isBusyFile(FileInfo fileInfo) { FileStream stream = null; try { stream = fileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None); } catch (IOException) { return true; } finally { if (stream != null) stream.Close(); } return false; } static void Main(string[] args) { string pathToFile = @"C:\Users\isnullxbh\Downloads\debian-distro.iso"; FileInfo fileInfo = new FileInfo(pathToFile); while (isBusyFile(fileInfo)) { Console.WriteLine("\nisBusy..."); Thread.Sleep(2000); } System.Diagnostics.Process.Start(pathToFile); } } }
Source: https://ru.stackoverflow.com/questions/557529/
All Articles