@@ -269,8 +269,27 @@ func DeleteFiles(files ...string) (errs []error) {
269269
270270// DirsPath method returns all directories absolute path from given base path recursively.
271271func DirsPath (basePath string , recursive bool ) (pdirs []string , err error ) {
272+ return DirsPathExcludes (basePath , recursive , Excludes {})
273+ }
274+
275+ // DirsPathExcludes method returns all directories absolute path from given base path recursively
276+ // excluding the excludes list.
277+ func DirsPathExcludes (basePath string , recursive bool , excludes Excludes ) (pdirs []string , err error ) {
278+ if err = excludes .Validate (); err != nil {
279+ return
280+ }
281+
272282 if recursive {
273283 err = Walk (basePath , func (srcPath string , info os.FileInfo , err error ) error {
284+ if excludes .Match (filepath .Base (srcPath )) {
285+ if info .IsDir () {
286+ // excluding directory
287+ return filepath .SkipDir
288+ }
289+ // excluding file
290+ return nil
291+ }
292+
274293 if info .IsDir () {
275294 pdirs = append (pdirs , srcPath )
276295 }
@@ -286,7 +305,7 @@ func DirsPath(basePath string, recursive bool) (pdirs []string, err error) {
286305 }
287306
288307 for _ , v := range list {
289- if v .IsDir () {
308+ if v .IsDir () && ! excludes . Match ( v . Name ()) {
290309 pdirs = append (pdirs , filepath .Join (basePath , v .Name ()))
291310 }
292311 }
@@ -296,8 +315,27 @@ func DirsPath(basePath string, recursive bool) (pdirs []string, err error) {
296315
297316// FilesPath method returns all files absolute path from given base path recursively.
298317func FilesPath (basePath string , recursive bool ) (files []string , err error ) {
318+ return FilesPathExcludes (basePath , recursive , Excludes {})
319+ }
320+
321+ // FilesPathExcludes method returns all files absolute path from given base path recursively
322+ // excluding the excludes list.
323+ func FilesPathExcludes (basePath string , recursive bool , excludes Excludes ) (files []string , err error ) {
324+ if err = excludes .Validate (); err != nil {
325+ return
326+ }
327+
299328 if recursive {
300329 err = Walk (basePath , func (srcPath string , info os.FileInfo , err error ) error {
330+ if excludes .Match (filepath .Base (srcPath )) {
331+ if info .IsDir () {
332+ // excluding directory
333+ return filepath .SkipDir
334+ }
335+ // excluding file
336+ return nil
337+ }
338+
301339 if ! info .IsDir () {
302340 files = append (files , srcPath )
303341 }
@@ -313,7 +351,7 @@ func FilesPath(basePath string, recursive bool) (files []string, err error) {
313351 }
314352
315353 for _ , v := range list {
316- if ! v .IsDir () {
354+ if ! v .IsDir () && ! excludes . Match ( v . Name ()) {
317355 files = append (files , filepath .Join (basePath , v .Name ()))
318356 }
319357 }
0 commit comments