Created
September 10, 2014 23:22
-
-
Save Robert-McGinley/d8e9f467c2aaf7ab918d to your computer and use it in GitHub Desktop.
FilesystemUtils.cs - Utility class for some common filesystem attribute checks (That I regularly forget how to do)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// =========================================================================== | |
// File: FilesystemUtils.cs | |
// | |
// Created on 9/10/2014 by Robert McGinley (robert.mcginley@gmail.com) | |
// | |
// This file, project or solution may be under one or more copyrights, trademarks or licenses | |
// not covered in this file header. Lack of copyright, trademark or license notice in this | |
// file header does not negate the applicability of any such restrictions or agreements. | |
// Please see the author or program's website for details on any applicable licenses, | |
// trademarks copyrights or other assorted legalese. | |
// | |
// | |
// =========================================================================== | |
// | |
namespace System.IO | |
{ | |
public static class FilesystemUtils | |
{ | |
#region Public methods | |
/// <summary> | |
/// Determines whether the specified path is directory. | |
/// </summary> | |
/// <param name="path">The path.</param> | |
/// <returns>True if the specified path is a directory. False if not.</returns> | |
public static bool IsDirectory(string path) | |
{ | |
return (File.GetAttributes(@path) & FileAttributes.Directory) == FileAttributes.Directory; | |
} | |
/// <summary> | |
/// Determines whether the specified path is file. | |
/// </summary> | |
/// <param name="path">The path.</param> | |
/// <returns>True if the specified path is a file. False if not.</returns> | |
public static bool IsFile(string path) | |
{ | |
return !IsDirectory(@path); | |
} | |
/// <summary> | |
/// Determines whether the specified path is compressed. | |
/// </summary> | |
/// <param name="path">The path.</param> | |
/// <returns>True if the file/directory is compressed. False if not.</returns> | |
public static bool IsCompressed(string path) | |
{ | |
return (File.GetAttributes(@path) & FileAttributes.Compressed) == FileAttributes.Compressed; | |
} | |
#endregion | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment