Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' ***********************************************************************
- ' Author : Elektro
- ' Modified : 31-January-2018
- ' ***********************************************************************
- #Region " Option Statements "
- Option Strict On
- Option Explicit On
- Option Infer Off
- #End Region
- #Region " Imports "
- Imports System.IO
- #End Region
- #Region " FileUtil "
- ' Namespace IO.Tools
- Public NotInheritable Class FileUtil
- #Region " Public Methods "
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the files those matches the criteria inside the specified directory and/or sub-directories.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim files As List(Of FileInfo) =
- ''' GetFiles("C:\Windows\System32", SearchOption.AllDirectories).ToList
- '''
- ''' Dim files As IEnumerable(Of FileInfo) =
- ''' GetFiles(dirPath:="C:\Windows\System32",
- ''' searchOption:=SearchOption.TopDirectoryOnly,
- ''' fileNamePatterns:={"*"},
- ''' fileExtPatterns:={"*.dll", "*.exe"},
- ''' ignoreCase:=True,
- ''' throwOnError:=True)
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="dirPath">
- ''' The root directory path to search for files.
- ''' </param>
- '''
- ''' <param name="searchOption">
- ''' The searching mode.
- ''' </param>
- '''
- ''' <param name="fileNamePatterns">
- ''' The file name pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="fileExtPatterns">
- ''' The file extension pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="ignoreCase">
- ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
- ''' </param>
- '''
- ''' <param name="throwOnError">
- ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' An <see cref="IEnumerable(Of FileInfo)"/> instance containing the files information.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shared Function GetFiles(ByVal dirPath As String,
- ByVal searchOption As Global.System.IO.SearchOption,
- Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal ignoreCase As Boolean = True,
- Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of FileInfo)
- Return FileDirSearcher.GetFiles(dirPath, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the files those matches the criteria inside the specified directory and/or sub-directories.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim files As List(Of FileInfo) =
- ''' GetFiles("C:\Windows\System32", SearchOption.AllDirectories).ToList
- '''
- ''' Dim files As IEnumerable(Of FileInfo) =
- ''' GetFiles(dirPath:="C:\Windows\System32",
- ''' searchOption:=SearchOption.TopDirectoryOnly,
- ''' fileNamePatterns:={"*"},
- ''' fileExtPatterns:={"*.dll", "*.exe"},
- ''' ignoreCase:=True,
- ''' throwOnError:=True)
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="dir">
- ''' The root directory path to search for files.
- ''' </param>
- '''
- ''' <param name="searchOption">
- ''' The searching mode.
- ''' </param>
- '''
- ''' <param name="fileNamePatterns">
- ''' The file name pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="fileExtPatterns">
- ''' The file extension pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="ignoreCase">
- ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
- ''' </param>
- '''
- ''' <param name="throwOnError">
- ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' An <see cref="IEnumerable(Of FileInfo)"/> instance containing the files information.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shared Function GetFiles(ByVal dir As DirectoryInfo,
- ByVal searchOption As Global.System.IO.SearchOption,
- Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal ignoreCase As Boolean = True,
- Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of FileInfo)
- Return FileDirSearcher.GetFiles(dir.FullName, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the filepaths those matches the criteria inside the specified directory and/or sub-directories.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim filePaths As List(Of String) =
- ''' GetFilePaths("C:\Windows\System32", SearchOption.AllDirectories).ToList
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="dirPath">
- ''' The root directory path to search for files.
- ''' </param>
- '''
- ''' <param name="searchOption">
- ''' The searching mode.
- ''' </param>
- '''
- ''' <param name="fileNamePatterns">
- ''' The file name pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="fileExtPatterns">
- ''' The file extension pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="ignoreCase">
- ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
- ''' </param>
- '''
- ''' <param name="throwOnError">
- ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' An <see cref="IEnumerable(Of String)"/> instance containing the filepaths.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shared Function GetFilePaths(ByVal dirPath As String,
- ByVal searchOption As Global.System.IO.SearchOption,
- Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal ignoreCase As Boolean = True,
- Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of String)
- Return FileDirSearcher.GetFilePaths(dirPath, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
- End Function
- ''' ----------------------------------------------------------------------------------------------------
- ''' <summary>
- ''' Gets the filepaths those matches the criteria inside the specified directory and/or sub-directories.
- ''' </summary>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <example> This is a code example.
- ''' <code>
- ''' Dim filePaths As List(Of String) =
- ''' GetFilePaths("C:\Windows\System32", SearchOption.AllDirectories).ToList
- ''' </code>
- ''' </example>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <param name="dir">
- ''' The root directory path to search for files.
- ''' </param>
- '''
- ''' <param name="searchOption">
- ''' The searching mode.
- ''' </param>
- '''
- ''' <param name="fileNamePatterns">
- ''' The file name pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="fileExtPatterns">
- ''' The file extension pattern(s) to match.
- ''' </param>
- '''
- ''' <param name="ignoreCase">
- ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
- ''' </param>
- '''
- ''' <param name="throwOnError">
- ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
- ''' </param>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <returns>
- ''' An <see cref="IEnumerable(Of String)"/> instance containing the filepaths.
- ''' </returns>
- ''' ----------------------------------------------------------------------------------------------------
- ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
- ''' </exception>
- ''' ----------------------------------------------------------------------------------------------------
- <DebuggerStepThrough>
- Public Shared Function GetFilePaths(ByVal dir As DirectoryInfo,
- ByVal searchOption As Global.System.IO.SearchOption,
- Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
- Optional ByVal ignoreCase As Boolean = True,
- Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of String)
- Return FileDirSearcher.GetFilePaths(dir.FullName, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
- End Function
- #End Region
- End Class
- ' End Namespace
- #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement