@@ -20,9 +20,10 @@ object IOUtil {
20
20
21
21
/**
22
22
* Read a FHIR resource from given path or default path (within project resources)
23
- * @param resourcePath Given file path
24
- * @param defaultPath Default resource path (within project resources)
25
- * @param rtype Resource type
23
+ *
24
+ * @param resourcePath Given file path
25
+ * @param defaultPath Default resource path (within project resources)
26
+ * @param rtype Resource type
26
27
* @return
27
28
*/
28
29
def readResource (resourcePath : Option [String ], defaultPath : String , rtype : String ): Resource = {
@@ -43,7 +44,8 @@ object IOUtil {
43
44
44
45
/**
45
46
* Read a FHIR resource from given File path
46
- * @param filePath File path
47
+ *
48
+ * @param filePath File path
47
49
* @return
48
50
*/
49
51
def readResource (filePath : String ): Resource = {
@@ -52,7 +54,8 @@ object IOUtil {
52
54
53
55
/**
54
56
* Read a FHIR resource from project resources with a path
55
- * @param resourcePath Resource path
57
+ *
58
+ * @param resourcePath Resource path
56
59
* @return
57
60
*/
58
61
def readInnerResource (resourcePath : String ): Resource = {
@@ -93,7 +96,7 @@ object IOUtil {
93
96
if (! givenFile.isDirectory)
94
97
throw new InitializationException (s " Given path ' $path' is not a folder or zip file ... " )
95
98
// Given as folder
96
- getFilesFromFolder(folder = givenFile, withExtension = None , recursively = Some ( true ) )
99
+ getFilesFromFolder(folder = givenFile, recursively = true , ignoreHidden = true , withExtension = None )
97
100
.map(file => {
98
101
try {
99
102
parseResource(new InputStreamReader (BOMInputStream .builder.setInputStream(new FileInputStream (file)).get()), file.getAbsolutePath)
@@ -120,19 +123,30 @@ object IOUtil {
120
123
* Get the list of files from the given folder.
121
124
*
122
125
* @param folder The folder to retrieve the files from.
126
+ * @param recursively If true, the folder will be searched recursively to retrieve all files within.
127
+ * @param ignoreHidden If true, hidden files and directories will be excluded from the result.
123
128
* @param withExtension An optional extension (e.g., .json) if the files need to be filtered.
124
- * @param recursively If exists and true, the folder will be searched recursively to retrieve all files within.
125
- * @return
129
+ * @return A sequence of files matching the criteria.
126
130
*/
127
- def getFilesFromFolder (folder : File , withExtension : Option [String ], recursively : Option [Boolean ]): Seq [File ] = {
131
+ def getFilesFromFolder (
132
+ folder : File ,
133
+ recursively : Boolean ,
134
+ ignoreHidden : Boolean ,
135
+ withExtension : Option [String ]
136
+ ): Seq [File ] = {
128
137
if (folder.exists && folder.isDirectory) {
129
138
val files = folder.listFiles().toSeq // List all available files in the given folder
139
+
140
+ // Filter hidden files if ignoreHidden is true
141
+ val nonHiddenFiles = if (ignoreHidden) files.filterNot(f => f.isHidden || f.getName.startsWith(" ." )) else files
142
+
130
143
val filteredFiles = withExtension
131
- .map(ext => files .filter(_.getName.endsWith(ext))).getOrElse(files )
144
+ .map(ext => nonHiddenFiles .filter(_.getName.endsWith(ext))).getOrElse(nonHiddenFiles )
132
145
.filterNot(_.isDirectory)
133
- if (recursively.contains(true )) {
134
- val subFolders = files.filter(_.isDirectory)
135
- filteredFiles ++ subFolders.flatMap(f => getFilesFromFolder(f, withExtension, recursively))
146
+
147
+ if (recursively) {
148
+ val subFolders = nonHiddenFiles.filter(_.isDirectory)
149
+ filteredFiles ++ subFolders.flatMap(f => getFilesFromFolder(f, recursively, ignoreHidden, withExtension))
136
150
} else {
137
151
filteredFiles
138
152
}
@@ -141,8 +155,10 @@ object IOUtil {
141
155
}
142
156
}
143
157
158
+
144
159
/**
145
160
* Given a filename, removes its extension if an extension exists (e.g., admissions.json -> admissions)
161
+ *
146
162
* @param fileName
147
163
* @return
148
164
*/
@@ -254,8 +270,9 @@ object IOUtil {
254
270
255
271
/**
256
272
* Parse a JSON resource
257
- * @param reader Reader
258
- * @param path File path it is read from
273
+ *
274
+ * @param reader Reader
275
+ * @param path File path it is read from
259
276
* @return
260
277
*/
261
278
private def parseResource (reader : Reader , path : String ): Resource = {
0 commit comments