@@ -35,6 +35,19 @@ func init() {
35
35
}
36
36
}
37
37
38
+ // Function to test if the given
39
+ // directory/file exists or not
40
+ func dirExist (path string ) (bool , error ) {
41
+ _ , err := os .Stat (path )
42
+ if err == nil {
43
+ return true , nil
44
+ }
45
+ if os .IsNotExist (err ) {
46
+ return false , nil
47
+ }
48
+ return false , err
49
+ }
50
+
38
51
// list all the files of a given directory
39
52
func visit (root string ) ([]string , error ) {
40
53
var files []string
@@ -220,8 +233,16 @@ func main() {
220
233
221
234
for _ , key := range paths .([]interface {}) {
222
235
for _ , file := range key .(map [interface {}]interface {}) {
223
- filePath := fmt .Sprintf ("%s/%s" , dir , file )
224
- fi , err := os .Stat (filePath )
236
+ PathofFile := fmt .Sprintf ("%s/%s" , dir , file )
237
+ checkDir , err := dirExist (PathofFile )
238
+ if err != nil {
239
+ fmt .Printf ("Some issue with directories" )
240
+ continue
241
+ }
242
+ if checkDir == false {
243
+ continue
244
+ }
245
+ fi , err := os .Stat (PathofFile )
225
246
if err != nil {
226
247
fmt .Println (err )
227
248
return
@@ -232,7 +253,7 @@ func main() {
232
253
switch mode := fi .Mode (); {
233
254
case mode .IsRegular ():
234
255
doc := etree .NewDocument ()
235
- if err := doc .ReadFromFile (filePath ); err != nil {
256
+ if err := doc .ReadFromFile (PathofFile ); err != nil {
236
257
panic (err )
237
258
}
238
259
// Parsing AndroidManifest for any API keys in there
@@ -252,12 +273,12 @@ func main() {
252
273
}
253
274
// Just listing files of raw and xml directory
254
275
case mode .IsDir ():
255
- if filepath .Base (filePath ) == "xml" {
276
+ if filepath .Base (PathofFile ) == "xml" {
256
277
fmt .Printf ("%s:\n " , "XML-files" )
257
278
} else {
258
279
fmt .Printf ("%s:\n " , "raw-files" )
259
280
}
260
- files , err := visit (filePath )
281
+ files , err := visit (PathofFile )
261
282
if err != nil {
262
283
fmt .Println (err )
263
284
}
0 commit comments