1 | #Region "Microsoft.VisualBasic::b7202c8182af67db8c9484cd28e50bfd, Microsoft.VisualBasic.Core\Extensions\IO\Path\Includes.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Class Includes |
35 | ' |
36 | ' Constructor: (+1 Overloads) Sub New |
37 | ' |
38 | ' Function: GetPath, ToString |
39 | ' |
40 | ' Sub: Add |
41 | ' |
42 | ' |
43 | ' /********************************************************************************/ |
44 | |
45 | #End Region |
46 | |
47 | Imports Microsoft.VisualBasic.Language |
48 | Imports Microsoft.VisualBasic.Serialization.JSON |
49 | |
50 | Namespace FileIO.Path |
51 | |
52 | ''' <summary> |
53 | ''' File includes search tools |
54 | ''' </summary> |
55 | Public Class Includes |
56 | |
57 | Dim __innerDIRs As List(Of String) |
58 | |
59 | Sub New(ParamArray DIR As String()) |
60 | __innerDIRs = New List(Of String)(DIR) |
61 | End Sub |
62 | |
63 | ''' <summary> |
64 | ''' Add includes directory into the search path. |
65 | ''' </summary> |
66 | ''' <param name="DIR"></param> |
67 | Public Sub Add(DIR As String) |
68 | __innerDIRs += DIR |
69 | End Sub |
70 | |
71 | ''' <summary> |
72 | ''' Get the absolutely file path from the includes file's relative path. |
73 | ''' </summary> |
74 | ''' <param name="relPath"></param> |
75 | ''' <returns></returns> |
76 | Public Function GetPath(relPath As String) As String |
77 | For Each DIR As String In __innerDIRs |
78 | Dim path As String = DIR & "/" & relPath |
79 | path = FileIO.FileSystem.GetFileInfo(path).FullName |
80 | If path.FileExists Then |
81 | Return path |
82 | End If |
83 | Next |
84 | |
85 | Return Nothing |
86 | End Function |
87 | |
88 | Public Overrides Function ToString() As String |
89 | Return "Searchs in directories: " & __innerDIRs.GetJson |
90 | End Function |
91 | End Class |
92 | End Namespace |