88 lines
2.7 KiB
C#
88 lines
2.7 KiB
C#
using Sarand.Core.Base;
|
|
using Sarand.Core.IO;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Sarand.OperationsMgr.Win.Dbas.Utils
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Static implementations of fucntions required by FileUtil.
|
|
/// </summary>
|
|
public class OpnFileUtil
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Initialise statics.
|
|
public static void InitStatics ()
|
|
{
|
|
FileUtil.DirectoryExists = IsDirectory;
|
|
FileUtil.DirectoryGetParent = GetParentDirectory;
|
|
FileUtil.DirectoryCreateDirectory = CreateDirectory;
|
|
FileUtil.FileExists = IsFile;
|
|
FileUtil.FileReadAllLines = FileReadAllLines;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// D i r e c t o r y
|
|
//-------------------------------------------------------------------
|
|
public static bool IsDirectory (String directoryPath)
|
|
{
|
|
try
|
|
{
|
|
return Directory.Exists(directoryPath);
|
|
}
|
|
catch (Exception exc) { Logger.Debug("SbmFileUtil.IsDirectory " + exc.GetType().Name + ": " + exc.Message); }
|
|
return false;
|
|
}
|
|
public static String GetParentDirectory (String filepath)
|
|
{
|
|
try
|
|
{
|
|
DirectoryInfo parentDirectoryInfo = Directory.GetParent(filepath);
|
|
if (parentDirectoryInfo != null)
|
|
return parentDirectoryInfo.FullName;
|
|
}
|
|
catch (Exception exc) { Logger.Debug("SbmFileUtil.GetParentDirectory " + exc.GetType().Name + ": " + exc.Message); }
|
|
return String.Empty;
|
|
}
|
|
public static bool CreateDirectory (String directoryPath)
|
|
{
|
|
try
|
|
{
|
|
DirectoryInfo info = Directory.CreateDirectory(directoryPath);
|
|
return info.Exists;
|
|
}
|
|
catch (Exception exc) { Logger.Debug("SbmFileUtil.CreateDirectory " + exc.GetType().Name + ": " + exc.Message); }
|
|
return false;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
// F i l e
|
|
//-------------------------------------------------------------------
|
|
public static bool IsFile (String filePath)
|
|
{
|
|
try
|
|
{
|
|
return File.Exists(filePath);
|
|
}
|
|
catch (Exception exc) { Logger.Debug("SbmFileUtil.IsFile " + exc.GetType().Name + ": " + exc.Message); }
|
|
return false;
|
|
}
|
|
public static String[] FileReadAllLines (String filePath)
|
|
{
|
|
try
|
|
{
|
|
return File.ReadAllLines(filePath);
|
|
}
|
|
catch (Exception exc) { Logger.Debug("SbmFileUtil.FileReadAllLines " + exc.GetType().Name + ": " + exc.Message); }
|
|
return new String[0];
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|