Net.Bluewalk.DotNetUtils/Extensions/FileInfoExtensions.cs
/// <summary>
/// Determines whether a file is locked by the OS.
/// </summary>
/// <param name="file">The file.</param>
/// <returns><c>true</c> if locked; otherwise, <c>false</c>.</returns>
Determines whether a file is locked by the OS.
Determines whether a file is locked by the OS .
public static bool IsLocked(this FileInfo file)
        {
            FileStream stream = null;
            try
            {
                stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None);
            }
            catch (IOException)
            {
                return true;
            }
            finally
            {
                stream?.Close();
            }
            return false;
        }
public static bool IsLocked ( this FileInfo file ) { FileStream stream = null ; try { stream = file . Open ( FileMode . Open , FileAccess . Read , FileShare . None ) ; } catch ( IOException ) { return true ; } finally { stream ? . Close ( ) ; } return false ; }
Determines whether a file is locked by the OS.
Determines whether a file is locked by the OS .
//the file is unavailable because it is: //still being written to //or being processed by another thread //or does not exist (has already been processed) //file is not locked
None
FileInfo
this
file
None