47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using GeneralApi.IntegrationUtility.Common;
|
|
using log4net;
|
|
using Microsoft.Practices.ServiceLocation;
|
|
using Taloyhtio.GeneralApi.Common.Extensions;
|
|
|
|
namespace Taloyhtio.GeneralApi.IntegrationUtility.Common
|
|
{
|
|
public static class FileUtilities
|
|
{
|
|
private static ILog logger = ServiceLocator.Current.GetInstance<ILog>();
|
|
|
|
public static void EnsureFolderExists(string path)
|
|
{
|
|
try
|
|
{
|
|
if (string.IsNullOrEmpty(path))
|
|
{
|
|
return;
|
|
}
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
logger.ErrorFormat(string.Format("{0}\n{1}", x.Message, x.StackTrace));
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public static string AddCurrentTimeToFileName(string fileName)
|
|
{
|
|
if (string.IsNullOrEmpty(fileName))
|
|
{
|
|
logger.Error("File name is empty");
|
|
}
|
|
return string.Format("{0}_{1}", DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss_fffffff"), fileName);
|
|
}
|
|
}
|
|
}
|