85 lines
2.7 KiB
C#
85 lines
2.7 KiB
C#
using Sarand.Net.Standard.Base.App;
|
|
using Sarand.Net.Standard.Base.IO;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Utils
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Static implementations of fucntions required by FileUtil.
|
|
/// </summary>
|
|
public class SbmFileUtil
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// 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) { SaLogger.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) { SaLogger.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) { SaLogger.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) { SaLogger.Debug("SbmFileUtil.IsFile " + exc.GetType().Name + ": " + exc.Message); }
|
|
return false;
|
|
}
|
|
public static String[] FileReadAllLines(String filePath)
|
|
{
|
|
try
|
|
{
|
|
return File.ReadAllLines(filePath);
|
|
}
|
|
catch (Exception exc) { SaLogger.Debug("SbmFileUtil.FileReadAllLines " + exc.GetType().Name + ": " + exc.Message); }
|
|
return new String[0];
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|