Comments (3)
Hi @chanduthedev - scandir should be able to do this quite easily. If you know that the depth is always 2 (one master folder and sub-folders), then you can make a function that does a scandir loop within a scandir loop: scan_2_deep()
in the example below. If the depth is variable, you'd have to make some kind of recursive function: one such function that scans n
deep is shown in the example as scan_n_deep()
. Here's a Python 3 program showing this:
import os
import sys
def scan_2_deep(path):
for entry in os.scandir(path):
if not entry.is_dir():
# Skip non-directories in master folder
continue
for sub_entry in os.scandir(entry.path):
if not sub_entry.is_file():
# Skip non-files in sub-folder
continue
print(sub_entry.path)
def scan_n_deep(path, n):
for entry in os.scandir(path):
if entry.is_dir():
if n > 1:
scan_n_deep(entry.path, n-1)
elif n == 1:
print(entry.path)
#scan_2_deep(sys.argv[1])
scan_n_deep(sys.argv[1], int(sys.argv[2]))
Does that help?
from scandir.
Thank you for the quick reply @benhoyt. This scan_2_deep method basically iterate all the folders one by one rite. Same logic I implemented before posting this question. It was taking around 13-14mins to read all ~4million files from 2million folders.
I also tried with your method scan_2_deep
method, it also took around 13mins 6 secs. where as existing (paths.list_images()
in python) method i used took 14mins 21sec.
There is very less much improvement of iterating through over folders than paths.list_images()
. I will be using paths.list_images()
.
Thank you so much for your quick response.
from scandir.
Sounds good!
from scandir.
Related Issues (20)
- scandir(dir_fd) HOT 5
- scandir 1.9.0 is broken on openindiana HOT 7
- scandir 1.9.0 broken in Python 2.7.13 HOT 7
- drop old/dead pythons? HOT 9
- test on py37? HOT 2
- pypy3 stat issue HOT 2
- preparing changelog for next release HOT 1
- Request for new release to PyPI >= 1.9.0 HOT 1
- Fix locale/unicode test failures on FreeBSD HOT 1
- Error from running setup.py install on python 2.7.5 win HOT 5
- Difference between scandir.walk() and os.walk() HOT 4
- The macOS wheels produced by scandir are overly restrictive in their platform HOT 1
- Wheel support for linux aarch64 HOT 1
- some doubt about your another project :pygit HOT 3
- GIL is not released when dir_entry.stat does a stat syscall HOT 6
- Running on Outdated Python and OS HOT 2
- Windows MAX_PATH limitation on inode call HOT 6
- module FTBFS on python3.9 and 3.10 HOT 2
- 3 fields are labelled "unnamed field" in `repr(scandir.DirEntry.stat())` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scandir.