Advertisement
Guest User

Untitled

a guest
Apr 14th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.18 KB | None | 0 0
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 31-January-2018
  4. ' ***********************************************************************
  5.  
  6. #Region " Option Statements "
  7.  
  8. Option Strict On
  9. Option Explicit On
  10. Option Infer Off
  11.  
  12. #End Region
  13.  
  14. #Region " Imports "
  15.  
  16. Imports System.IO
  17.  
  18. #End Region
  19.  
  20. #Region " FileUtil "
  21.  
  22. ' Namespace IO.Tools
  23.  
  24.  Public NotInheritable Class FileUtil
  25.  
  26. #Region " Public Methods "
  27.  
  28.         ''' ----------------------------------------------------------------------------------------------------
  29.         ''' <summary>
  30.         ''' Gets the files those matches the criteria inside the specified directory and/or sub-directories.
  31.         ''' </summary>
  32.         ''' ----------------------------------------------------------------------------------------------------
  33.         ''' <example> This is a code example.
  34.         ''' <code>
  35.         ''' Dim files As List(Of FileInfo) =
  36.         '''     GetFiles("C:\Windows\System32", SearchOption.AllDirectories).ToList
  37.         '''
  38.         ''' Dim files As IEnumerable(Of FileInfo) =
  39.         '''     GetFiles(dirPath:="C:\Windows\System32",
  40.         '''              searchOption:=SearchOption.TopDirectoryOnly,
  41.         '''              fileNamePatterns:={"*"},
  42.         '''              fileExtPatterns:={"*.dll", "*.exe"},
  43.         '''              ignoreCase:=True,
  44.         '''              throwOnError:=True)
  45.         ''' </code>
  46.         ''' </example>
  47.         ''' ----------------------------------------------------------------------------------------------------
  48.         ''' <param name="dirPath">
  49.         ''' The root directory path to search for files.
  50.         ''' </param>
  51.         '''
  52.         ''' <param name="searchOption">
  53.         ''' The searching mode.
  54.         ''' </param>
  55.         '''
  56.         ''' <param name="fileNamePatterns">
  57.         ''' The file name pattern(s) to match.
  58.         ''' </param>
  59.         '''
  60.         ''' <param name="fileExtPatterns">
  61.         ''' The file extension pattern(s) to match.
  62.         ''' </param>
  63.         '''
  64.         ''' <param name="ignoreCase">
  65.         ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
  66.         ''' </param>
  67.         '''
  68.         ''' <param name="throwOnError">
  69.         ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
  70.         ''' </param>
  71.         ''' ----------------------------------------------------------------------------------------------------
  72.         ''' <returns>
  73.         ''' An <see cref="IEnumerable(Of FileInfo)"/> instance containing the files information.
  74.         ''' </returns>
  75.         ''' ----------------------------------------------------------------------------------------------------
  76.         ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
  77.         ''' </exception>
  78.         ''' ----------------------------------------------------------------------------------------------------
  79.         <DebuggerStepThrough>
  80.         Public Shared Function GetFiles(ByVal dirPath As String,
  81.                                         ByVal searchOption As Global.System.IO.SearchOption,
  82.                                         Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
  83.                                         Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
  84.                                         Optional ByVal ignoreCase As Boolean = True,
  85.                                         Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of FileInfo)
  86.  
  87.             Return FileDirSearcher.GetFiles(dirPath, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
  88.  
  89.         End Function
  90.  
  91.         ''' ----------------------------------------------------------------------------------------------------
  92.         ''' <summary>
  93.         ''' Gets the files those matches the criteria inside the specified directory and/or sub-directories.
  94.         ''' </summary>
  95.         ''' ----------------------------------------------------------------------------------------------------
  96.         ''' <example> This is a code example.
  97.         ''' <code>
  98.         ''' Dim files As List(Of FileInfo) =
  99.         '''     GetFiles("C:\Windows\System32", SearchOption.AllDirectories).ToList
  100.         '''
  101.         ''' Dim files As IEnumerable(Of FileInfo) =
  102.         '''     GetFiles(dirPath:="C:\Windows\System32",
  103.         '''              searchOption:=SearchOption.TopDirectoryOnly,
  104.         '''              fileNamePatterns:={"*"},
  105.         '''              fileExtPatterns:={"*.dll", "*.exe"},
  106.         '''              ignoreCase:=True,
  107.         '''              throwOnError:=True)
  108.         ''' </code>
  109.         ''' </example>
  110.         ''' ----------------------------------------------------------------------------------------------------
  111.         ''' <param name="dir">
  112.         ''' The root directory path to search for files.
  113.         ''' </param>
  114.         '''
  115.         ''' <param name="searchOption">
  116.         ''' The searching mode.
  117.         ''' </param>
  118.         '''
  119.         ''' <param name="fileNamePatterns">
  120.         ''' The file name pattern(s) to match.
  121.         ''' </param>
  122.         '''
  123.         ''' <param name="fileExtPatterns">
  124.         ''' The file extension pattern(s) to match.
  125.         ''' </param>
  126.         '''
  127.         ''' <param name="ignoreCase">
  128.         ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
  129.         ''' </param>
  130.         '''
  131.         ''' <param name="throwOnError">
  132.         ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
  133.         ''' </param>
  134.         ''' ----------------------------------------------------------------------------------------------------
  135.         ''' <returns>
  136.         ''' An <see cref="IEnumerable(Of FileInfo)"/> instance containing the files information.
  137.         ''' </returns>
  138.         ''' ----------------------------------------------------------------------------------------------------
  139.         ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
  140.         ''' </exception>
  141.         ''' ----------------------------------------------------------------------------------------------------
  142.         <DebuggerStepThrough>
  143.         Public Shared Function GetFiles(ByVal dir As DirectoryInfo,
  144.                                         ByVal searchOption As Global.System.IO.SearchOption,
  145.                                         Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
  146.                                         Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
  147.                                         Optional ByVal ignoreCase As Boolean = True,
  148.                                         Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of FileInfo)
  149.  
  150.             Return FileDirSearcher.GetFiles(dir.FullName, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
  151.  
  152.         End Function
  153.  
  154.         ''' ----------------------------------------------------------------------------------------------------
  155.         ''' <summary>
  156.         ''' Gets the filepaths those matches the criteria inside the specified directory and/or sub-directories.
  157.         ''' </summary>
  158.         ''' ----------------------------------------------------------------------------------------------------
  159.         ''' <example> This is a code example.
  160.         ''' <code>
  161.         ''' Dim filePaths As List(Of String) =
  162.         '''     GetFilePaths("C:\Windows\System32", SearchOption.AllDirectories).ToList
  163.         ''' </code>
  164.         ''' </example>
  165.         ''' ----------------------------------------------------------------------------------------------------
  166.         ''' <param name="dirPath">
  167.         ''' The root directory path to search for files.
  168.         ''' </param>
  169.         '''
  170.         ''' <param name="searchOption">
  171.         ''' The searching mode.
  172.         ''' </param>
  173.         '''
  174.         ''' <param name="fileNamePatterns">
  175.         ''' The file name pattern(s) to match.
  176.         ''' </param>
  177.         '''
  178.         ''' <param name="fileExtPatterns">
  179.         ''' The file extension pattern(s) to match.
  180.         ''' </param>
  181.         '''
  182.         ''' <param name="ignoreCase">
  183.         ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
  184.         ''' </param>
  185.         '''
  186.         ''' <param name="throwOnError">
  187.         ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
  188.         ''' </param>
  189.         ''' ----------------------------------------------------------------------------------------------------
  190.         ''' <returns>
  191.         ''' An <see cref="IEnumerable(Of String)"/> instance containing the filepaths.
  192.         ''' </returns>
  193.         ''' ----------------------------------------------------------------------------------------------------
  194.         ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
  195.         ''' </exception>
  196.         ''' ----------------------------------------------------------------------------------------------------
  197.         <DebuggerStepThrough>
  198.         Public Shared Function GetFilePaths(ByVal dirPath As String,
  199.                                             ByVal searchOption As Global.System.IO.SearchOption,
  200.                                             Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
  201.                                             Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
  202.                                             Optional ByVal ignoreCase As Boolean = True,
  203.                                             Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of String)
  204.  
  205.             Return FileDirSearcher.GetFilePaths(dirPath, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
  206.  
  207.         End Function
  208.  
  209.         ''' ----------------------------------------------------------------------------------------------------
  210.         ''' <summary>
  211.         ''' Gets the filepaths those matches the criteria inside the specified directory and/or sub-directories.
  212.         ''' </summary>
  213.         ''' ----------------------------------------------------------------------------------------------------
  214.         ''' <example> This is a code example.
  215.         ''' <code>
  216.         ''' Dim filePaths As List(Of String) =
  217.         '''     GetFilePaths("C:\Windows\System32", SearchOption.AllDirectories).ToList
  218.         ''' </code>
  219.         ''' </example>
  220.         ''' ----------------------------------------------------------------------------------------------------
  221.         ''' <param name="dir">
  222.         ''' The root directory path to search for files.
  223.         ''' </param>
  224.         '''
  225.         ''' <param name="searchOption">
  226.         ''' The searching mode.
  227.         ''' </param>
  228.         '''
  229.         ''' <param name="fileNamePatterns">
  230.         ''' The file name pattern(s) to match.
  231.         ''' </param>
  232.         '''
  233.         ''' <param name="fileExtPatterns">
  234.         ''' The file extension pattern(s) to match.
  235.         ''' </param>
  236.         '''
  237.         ''' <param name="ignoreCase">
  238.         ''' If <see langword="True"/>, ignores the comparing case of <paramref name="fileNamePatterns"/> and <paramref name="fileExtPatterns"/> patterns.
  239.         ''' </param>
  240.         '''
  241.         ''' <param name="throwOnError">
  242.         ''' If set to <see langword="True"/>, exceptions will be thrown, like access denied to file or directory.
  243.         ''' </param>
  244.         ''' ----------------------------------------------------------------------------------------------------
  245.         ''' <returns>
  246.         ''' An <see cref="IEnumerable(Of String)"/> instance containing the filepaths.
  247.         ''' </returns>
  248.         ''' ----------------------------------------------------------------------------------------------------
  249.         ''' <exception cref="Global.System.ArgumentException">dirPath or searchOption
  250.         ''' </exception>
  251.         ''' ----------------------------------------------------------------------------------------------------
  252.         <DebuggerStepThrough>
  253.         Public Shared Function GetFilePaths(ByVal dir As DirectoryInfo,
  254.                                             ByVal searchOption As Global.System.IO.SearchOption,
  255.                                             Optional ByVal fileNamePatterns As IEnumerable(Of String) = Nothing,
  256.                                             Optional ByVal fileExtPatterns As IEnumerable(Of String) = Nothing,
  257.                                             Optional ByVal ignoreCase As Boolean = True,
  258.                                             Optional ByVal throwOnError As Boolean = False) As IEnumerable(Of String)
  259.  
  260.             Return FileDirSearcher.GetFilePaths(dir.FullName, searchOption, fileNamePatterns, fileExtPatterns, ignoreCase, throwOnError)
  261.  
  262.         End Function
  263.  
  264. #End Region
  265.  
  266.     End Class
  267.  
  268. ' End Namespace
  269.  
  270. #End Region
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement