Operation folder DLL class

Source: Internet
Author: User

/// <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;
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.