/// <Summary>
/// Folder operation class
/// </Summary>
Public class DirOption
{
/// <Summary>
/// Whether to delete
/// </Summary>
Public enum OperateOption
{
// Delete
ExistDelete,
// Do not delete
ExistReturn
}
/// <Summary>
/// Create a directory
/// </Summary>
/// <Param name = "DirFullPath"> full directory path </param>
/// <Param name = "op"> whether to delete enumeration </param>
/// <Returns> </returns>
Public bool CreateDir (string DirFullPath, OperateOption op)
{
Try
{
If (! Directory. Exists (DirFullPath ))
{
Directory. CreateDirectory (DirFullPath );
}
Else if (op = OperateOption. ExistDelete)
{
Directory. Delete (DirFullPath, true );
Directory. CreateDirectory (DirFullPath );
}
Return true;
}
Catch
{
Return false;
}
}
/// <Summary>
/// Delete a directory
/// </Summary>
/// <Param name = "DirFullPath"> Delete path </param>
/// <Returns> </returns>
Public bool DeleteDir (string DirFullPath)
{
Try
{
If (Directory. Exists (DirFullPath ))
{
Directory. Delete (DirFullPath );
Return true;
}
Else
{
Return false;
}
}
Catch
{
Return false;
}
}
/// <Summary>
/// Obtain all files in the current file in the full path
/// </Summary>
/// <Param name = "DirFullPath"> </param>
/// <Returns> </returns>
Public string [] GetDirFiels (string DirFullPath)
{
String [] FileList = null;
If (Directory. Exists (DirFullPath ))
{
FileList = Directory. GetFiles (DirFullPath, "*. *", System. IO. SearchOption. TopDirectoryOnly );
Return FileList;
}
Else
{
Return null;
}
}
/// <Summary>
/// Search for objects in the specified path
/// </Summary>
/// <Param name = "DirFullPath"> </param>
/// <Param name = "fileType"> </param>
/// <Returns> </returns>
Public string [] GetDirFiels (string DirFullPath, string fileType)
{
String [] strFiles = null;
If (Directory. Exists (DirFullPath ))
{
StrFiles = Directory. GetFiles (DirFullPath, fileType, System. IO. SearchOption. TopDirectoryOnly );
}
Return strFiles;
}
/// <Summary>
/// Return whether to find the sub-directory file
/// </Summary>
/// <Param name = "DirFullPath"> </param>
/// <Param name = "so"> </param>
/// <Returns> </returns>
Public string [] GetDirFiles (string DirFullPath, System. IO. SearchOption so)
{
String [] strFiles = null;
If (Directory. Exists (DirFullPath ))
{
StrFiles = Directory. GetFiles (DirFullPath, "*. *", so );
}
Return strFiles;
}
/// <Summary>
/// Search for subdirectory files of the specified type
/// </Summary>
/// <Param name = "DirFullPath"> full path </param>
/// <Param name = "fileType"> file type </param>
/// <Param name = "so"> </param>
/// <Returns> </returns>
Public string [] GetDirFiles (string DirFullPath, string fileType, System. IO. SearchOption so)
{
String [] strFiles = null;
If (Directory. Exists (DirFullPath ))
{
StrFiles = Directory. GetFiles (DirFullPath, fileType, so );
}
Return strFiles;
}
}