0

I'm currently implementing a docker automation to check whether the number of files in the host mount is equal to docker container mount.

The thing I need to implements

cd <source\location\host>
ls | wc -l

I'm not getting proper value but when I converted the same into python using below code. Geting some other value which does not match with ls | wc -l

 files = folders = 0
        t = Timer(self._seconds, self._stop_loop)
        t.start()
        for _, dirnames, filenames in os.walk(path):
            if self._loop_stop:
                break
            # ^ this idiom means "we won't be using this value"
            files += len(filenames)
            folders += len(dirnames)
        t.cancel()
        return folders + files

Can anyone help me to identify if this is right approach. If there is an alternative way then kindly share with me.

Thanks in advance.

Aaditya R Krishnan
  • 495
  • 1
  • 10
  • 31
  • `ls | wc -l` is not a good way to find the number of files in a directory. It won't show hidden files, and it might format in multiple columns. See https://stackoverflow.com/a/20895338/1904146 – blueteeth Jun 10 '21 at 15:24
  • If you do `ls -1a | wc -l` is that (+/- 2) the same number that Python prints ? – blueteeth Jun 11 '21 at 10:44

0 Answers0