Allow recursive for plain directories

This commit is contained in:
Milan Nikolic
2023-08-23 13:16:30 +02:00
parent f0e2232e51
commit c34b4d0a98

View File

@@ -1324,6 +1324,28 @@ func (c *Convertor) Files(args []string) ([]string, error) {
return nil
}
walkDirs := func(fp string, f os.FileInfo, err error) error {
if f.IsDir() {
fs, err := os.ReadDir(filepath.Join(filepath.Dir(fp), f.Name()))
if err != nil {
return err
}
count := 0
for _, fn := range fs {
if !fn.IsDir() {
count++
}
}
if count > 1 {
files = append(files, fp)
}
}
return nil
}
for _, arg := range args {
path, err := filepath.Abs(arg)
if err != nil {
@@ -1367,10 +1389,16 @@ func (c *Convertor) Files(args []string) ([]string, error) {
if len(files) == 0 {
// append plain directory with images
if c.Opts.Recursive {
if err := filepath.Walk(path, walkDirs); err != nil {
return files, fmt.Errorf("%s: %w", arg, err)
}
} else {
files = append(files, path)
}
}
}
}
c.Nfiles = len(files)