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.

2
  • 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 stackoverflow.com/a/20895338/1904146 Commented Jun 10, 2021 at 15:24
  • If you do ls -1a | wc -l is that (+/- 2) the same number that Python prints ? Commented Jun 11, 2021 at 10:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.