You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+33-32Lines changed: 33 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,9 @@ Iterate large directories efficiently with python.
7
7
About
8
8
=====
9
9
10
-
``python-getdents`` is a simple wrapper around Linux system call ``getdents64`` (see ``man getdents`` for details). `More details <http://be-n.com/spw/you-can-list-a-million-files-in-a-directory-but-not-with-ls.html>`_ on approach.
10
+
``python-getdents`` is a simple wrapper around Linux system call ``getdents64`` (see ``man getdents`` for details).
11
11
12
-
TODO
13
-
====
14
-
15
-
* Verify that implementation works on platforms other than ``x86_64``.
12
+
Implementation is based on solution descibed in `You can list a directory containing 8 million files! But not with ls. <http://be-n.com/spw/you-can-list-a-million-files-in-a-directory-but-not-with-ls.html>`_ article by Ben Congleton.
16
13
17
14
Install
18
15
=======
@@ -45,51 +42,55 @@ Run tests
45
42
46
43
ulimit -v 33554432 && py.test tests/
47
44
48
-
Or
49
-
50
-
.. code-block:: sh
51
-
52
-
ulimit -v 33554432 && ./setup.py test
53
-
54
45
Usage
55
46
=====
56
47
57
48
.. code-block:: python
58
49
59
50
from getdents import getdents
60
51
61
-
for inode, type, name in getdents('/tmp', 32768):
52
+
for inode, type_, name in getdents("/tmp"):
62
53
print(name)
63
54
64
55
Advanced
65
56
--------
66
57
58
+
While ``getdents`` provides a convenient wrapper with ls-like filtering, you can use ``getdents_raw`` for more control:
59
+
67
60
.. code-block:: python
68
61
69
62
import os
70
-
from getdents import*
71
-
72
-
fd = os.open('/tmp', O_GETDENTS)
73
-
74
-
for inode, type, name in getdents_raw(fd, 2**20):
75
-
print({
76
-
DT_BLK: 'blockdev',
77
-
DT_CHR: 'chardev ',
78
-
DT_DIR: 'dir ',
79
-
DT_FIFO: 'pipe ',
80
-
DT_LNK: 'symlink ',
81
-
DT_REG: 'file ',
82
-
DT_SOCK: 'socket ',
83
-
DT_UNKNOWN: 'unknown ',
84
-
}[type], {
85
-
True: 'd',
86
-
False: '',
87
-
}[inode ==0],
88
-
name,
89
-
)
63
+
from getdents importDT_LNK, O_GETDENTS, getdents_raw
64
+
65
+
fd = os.open("/tmp", O_GETDENTS)
66
+
67
+
for inode, type_, name in getdents_raw(fd, 2**20):
0 commit comments