예제 #1
0
        /// <summary> Queries if a given file exists. </summary>
        /// <param name="filePath"> Full pathname of the file. </param>
        /// <param name="zeroByteFileCheck"> (Optional) The zero byte file check. </param>
        /// <returns> True if it succeeds, false if it fails. </returns>
        public bool FileExists(string filePath, ZeroByteFileOption zeroByteFileCheck = ZeroByteFileOption.DoNotCheck)
        {
            bool result = false;

            if (!String.IsNullOrWhiteSpace(filePath))
            {
                result = File.Exists(filePath);

                if (result && zeroByteFileCheck != ZeroByteFileOption.DoNotCheck)
                {
                    using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                    {
                        result = (fs.Length > Int32.MaxValue);

                        if (!result)
                        {
                            byte[] fileBytes = {};
                            if (fs.Length > 0)
                            {
                                using (var br = new BinaryReader(fs))
                                {
                                    fileBytes = br.ReadBytes((int)fs.Length);
                                }
                            }

                            result = (fileBytes.Length > 0);
                            if (!result)
                            {
                                if (zeroByteFileCheck == ZeroByteFileOption.DeleteFile)
                                {
                                    File.Delete(filePath);
                                    result = true;
                                }
                                else
                                {
                                    result = (zeroByteFileCheck == ZeroByteFileOption.ReturnTrue);
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
예제 #2
0
 /// <summary> Queries if a given file exists. </summary>
 /// <param name="fileName"> Filename of the file. </param>
 /// <param name="appDataSubFolder"> Pathname of the application data sub folder. </param>
 /// <param name="zeroByteFileCheck"> (Optional) The zero byte file check. </param>
 /// <returns> True if it succeeds, false if it fails. </returns>
 public bool FileExists(string fileName, string appDataSubFolder,
                        ZeroByteFileOption zeroByteFileCheck = ZeroByteFileOption.DoNotCheck)
 {
     return(FileExists(AppDataFilePath(fileName, appDataSubFolder), zeroByteFileCheck));
 }