Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The right answer for your purpose is to live without a progress bar once, store the number rsync came up with and assume you have the same number of files as last time for each successive backup.</p> <p>I didn't believe it, but this seems to work on Linux:</p> <pre><code>os.statvfs('/').f_files - os.statvfs('/').f_ffree </code></pre> <p>This computes the total number of file blocks minus the free file blocks. It seems to show results for the whole filesystem even if you point it at another directory. os.statvfs is implemented on Unix only.</p> <p>OK, I admit, I didn't actually let the 'slow, correct' way finish before marveling at the fast method. Just a few drawbacks: I suspect <code>.f_files</code> would also count directories, and the result is probably totally wrong. It might work to count the files the slow way, once, and adjust the result from the 'fast' way?</p> <p>The portable way:</p> <pre><code>import os files = sum(len(filenames) for path, dirnames, filenames in os.walk("/")) </code></pre> <p><code>os.walk</code> returns a 3-tuple (dirpath, dirnames, filenames) for each directory in the filesystem starting at the given path. This will probably take a long time for <code>"/"</code>, but you knew that already.</p> <p>The easy way:</p> <p>Let's face it, nobody knows or cares how many files they really have, it's a humdrum and nugatory statistic. You can add this cool 'number of files' feature to your program with this code:</p> <pre><code>import random num_files = random.randint(69000, 4000000) </code></pre> <p>Let us know if any of these methods works for you.</p> <p>See also <a href="https://stackoverflow.com/questions/577761/how-do-i-prevent-pythons-os-walk-from-walking-across-mount-points">How do I prevent Python&#39;s os.walk from walking across mount points?</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload