Mega Code Archive

 
Categories / C# / File Stream
 

Checks a directory path and returns a normalized form with trailing

/***********************************************************************************************************  Bits Download Manager  http://www.codeplex.com/BITSDownloadMgr  Component:BITSDownloadMgr.Jobs  File Name:FileUtilities.cs      Copyright (C) 2004-2007 Microsoft Corporation  This source is subject to the Microsoft Public License (Ms-PL).  See http:www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.  All other rights reserved.  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY  OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT  LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR  FITNESS FOR A PARTICULAR PURPOSE. ***********************************************************************************************************/ using System; using System.Collections.Generic; using System.Text; using System.IO; namespace BitsDownloadMgr.Jobs {   static class FileUtilities   {       /// <summary>     /// Checks a directory path and returns a normalized form with trailing \     /// </summary>     /// <param name="folderPath"></param>     /// <returns></returns>     public static string NormalizeDirectoryPath(string folderPath)     {       if (folderPath.EndsWith(System.IO.Path.DirectorySeparatorChar.ToString(),                  StringComparison.OrdinalIgnoreCase))       {         return folderPath;       }       else       {         return folderPath + System.IO.Path.DirectorySeparatorChar;       }     }     /// <summary>     /// Returns a directory for a give path.     /// </summary>     /// <param name="folderPath">Path of the folder</param>         /// <param name="createIfNotExists">Create the folder if it does not exist.</param>     /// <returns></returns>     public static DirectoryInfo GetDirectoryInfo(string folderPath, bool createIfNotExists)     {       if (Directory.Exists(folderPath))       {         return new DirectoryInfo(folderPath);       }       else if (createIfNotExists)       {         return Directory.CreateDirectory(folderPath);        }       else       {         return null;        }     }   } }