/// <summary> /// Sees if the file exists /// </summary> /// <remarks>Always use this to check for files in the scanners!</remarks> /// <param name="filePath">The filename (including path)</param> /// <returns> /// True if it exists or if the path should be skipped. Otherwise, false if the file path is empty or doesnt exist /// </returns> public static bool FileExists(string filePath) { if (string.IsNullOrEmpty(filePath)) { return(false); } string strFileName = string.Copy(filePath.Trim().ToLower()); // Remove quotes strFileName = UnqouteSpaces(strFileName); // Remove environment variables strFileName = Environment.ExpandEnvironmentVariables(strFileName); // Check for illegal characters if (FindAnyIllegalChars(strFileName)) { return(false); } // Check Drive Type VDTReturn ret = ValidDriveType(strFileName); if (ret == VDTReturn.InvalidDrive) { return(false); } else if (ret == VDTReturn.SkipCheck) { return(true); } // See if it is on exclude list if (ScanDlg.IsOnIgnoreList(strFileName)) { return(true); } // Now see if file exists if (File.Exists(strFileName)) { return(true); } if (PathFileExists(strFileName)) { return(true); } if (SearchPath(strFileName)) { return(true); } return(false); }
/// <summary> /// Sees if the directory exists /// </summary> /// <remarks>Always use this to check for directories in the scanners!</remarks> /// <param name="dirPath">The directory</param> /// <returns>True if it exists or if the path should be skipped. Otherwise, false if the file path is empty or doesnt exist</returns> public static bool DirExists(string dirPath) { if (string.IsNullOrEmpty(dirPath)) { return(false); } string strDirectory = string.Copy(dirPath.Trim().ToLower()); // Remove quotes strDirectory = UnqouteSpaces(strDirectory); // Expand environment variables strDirectory = Environment.ExpandEnvironmentVariables(strDirectory); // Check drive type VDTReturn ret = ValidDriveType(strDirectory); if (ret == VDTReturn.InvalidDrive) { return(false); } else if (ret == VDTReturn.SkipCheck) { return(true); } // Check for illegal chars if (FindAnyIllegalChars(strDirectory)) { return(false); } // See if it is on the exclude list if (ScanDlg.IsOnIgnoreList(strDirectory)) { return(true); } // Remove filename.ext and trailing backslash from path StringBuilder sb = new StringBuilder(strDirectory); if (PathRemoveFileSpec(sb)) { if (Directory.Exists(sb.ToString())) { return(true); } } if (Directory.Exists(strDirectory)) { return(true); } return(false); }