Skip to content

Instantly share code, notes, and snippets.

@Robert-McGinley
Created September 10, 2014 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robert-McGinley/d8e9f467c2aaf7ab918d to your computer and use it in GitHub Desktop.
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)
// ===========================================================================
// 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