Azavea.NijPredictivePolicing.Common.FileUtilities.SafePathEnsure C# (CSharp) Method

SafePathEnsure() public static method

Wrapper around PathEnsure() that doesn't throw exceptions. Returns "" on error and prints an error message to _log
public static SafePathEnsure ( string basepath ) : string
basepath string
return string
        public static string SafePathEnsure(string basepath, params string[] chunks)
        {
            try
            {

                //I'd rather do this here, than directly in the constructor or class definition.
                //The file system loves to throw exceptions, and I'd rather see em than a app 'exit'!
                //In Soviet Russia, computer throws things at YOU!!

                return FileUtilities.PathEnsure(basepath, chunks);
            }
            catch (Exception ex)
            {
                _log.Error("Error constructing path", ex);
            }
            return string.Empty;
        }

Usage Example

        /// <summary>
        /// Uses Ionic.Zip library to expand a file (without overwriting) to a given location
        /// </summary>
        /// <param name="basePath"></param>
        /// <param name="zipFileName"></param>
        /// <returns></returns>
        public static bool UnzipFileTo(string basePath, string zipFileName)
        {
            try
            {
                _log.DebugFormat("Unzipping {0}", Path.GetFileName(zipFileName));
                FileUtilities.SafePathEnsure(basePath);

                var zipFile = new ZipFile(zipFileName);
                zipFile.ExtractAll(basePath, ExtractExistingFileAction.DoNotOverwrite);

                _log.Debug("Unzipping... Done!");

                if (Settings.ShowFilePaths)
                {
                    _log.InfoFormat("Unzipped \"{0}\" to \"{1}\"", Path.GetFileName(zipFileName), basePath);
                }

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error("Error while unzipping file", ex);
            }
            return(false);
        }