Questions tagged [directory-walk]
28 questions
54
votes
17 answers
What is the Python way to walk a directory tree?
I feel that assigning files, and folders and doing the += [item] part is a bit hackish. Any suggestions? I'm using Python 3.2
from os import *
from os.path import *
def dir_contents(path):
contents = listdir(path)
files = []
folders =…

Mike
- 1,784
- 1
- 12
- 12
47
votes
5 answers
Quicker to os.walk or glob?
I'm messing around with file lookups in python on a large hard disk. I've been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to be quicker (for usual size directories).
Has anyone got any experience with…

joedborg
- 17,651
- 32
- 84
- 118
24
votes
10 answers
Is there a workaround for Java's poor performance on walking huge directories?
I am trying to process files one at a time that are stored over a network. Reading the files is fast due to buffering is not the issue. The problem I have is just listing the directories in a folder. I have at least 10k files per folder over many…

Pyrolistical
- 27,624
- 21
- 81
- 106
22
votes
5 answers
Hadoop MapReduce provide nested directories as job input
I'm working on a job that processes a nested directory structure, containing files on multiple levels:
one/
├── three/
│ └── four/
│ ├── baz.txt
│ ├── bleh.txt
│ └── foo.txt
└── two/
├── bar.txt
└── gaa.txt
When I add…

sa125
- 28,121
- 38
- 111
- 153
16
votes
2 answers
Can I make RecursiveDirectoryIterator skip unreadable directories?
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(".")) as $file) {
echo "$file\n";
}
Is there any way for this code to not throw UnexpectedValueException "failed to open dir: Permission denied" whenever there is a unreadable…

Kamil Szot
- 17,436
- 6
- 62
- 65
13
votes
3 answers
Java library to return a List for glob or Ant-like pattern "*foo/**/*.txt"?
I'm looking for a lib which would provide a method which would give me a list of files matching given Ant-like pattern.
For *foo/**/*.txt I'd get
foo/x.txt
foo/bar/baz/.txt
myfoo/baz/boo/bar.txt
etc. I know it's achievable with DirWalker and…

Ondra Žižka
- 43,948
- 41
- 217
- 277
9
votes
8 answers
unable to skip unreadable directories with RecursiveDirectoryIterator
I want to get a list of all the subdirectories and my below code works except when I have readonly permissions on certain folders.
In the below question it shows how to skip a directory with RecursiveDirectoryIterator
Can I make…

ak85
- 4,154
- 18
- 68
- 113
8
votes
4 answers
A Python walker that can ignore directories
I need a file system walker that I could instruct to ignore traversing
directories that I want to leave untouched, including all subdirectories
below that branch.
The os.walk and os.path.walk just don't do it.

Johan Carlsson
- 743
- 3
- 11
- 24
8
votes
5 answers
How to walk a directory in C
I am using glib in my application, and I see there are convenience wrappers in glib for C's remove, unlink and rmdir. But these only work on a single file or directory at a time.
As far as I can see, neither the C standard nor glib include any sort…

mlibby
- 6,567
- 1
- 32
- 41
3
votes
3 answers
Recursively walk a LARGE directory using Scala 2.8 continuations
Is it possible to recursively walk a directory using Scala continuations (introduced in 2.8)?
My directory contains millions of files, so I cannot use a Stream because I will get an out-of-memory. I am trying to write an Actor dispatch to have…

Ralph
- 31,584
- 38
- 145
- 282
3
votes
3 answers
URL tree walker in Python?
For URLs that show file trees, such as Pypi packages,
is there a small solid module to walk the URL tree and list it like ls -lR?
I gather (correct me) that there's no standard encoding of file attributes,
link types, size, date ... in html

denis
- 21,378
- 10
- 65
- 88
3
votes
3 answers
Working with File Attributes in C# .Net 2.0
So how can i recursively search a Folder and un-hide ALL files and sub folders in a directory? Like have it check each file and each folder... if they're hidden.. un-hide them. Iv been messing around with it all morning with no luck... i got all…

NightsEVil
- 507
- 2
- 13
- 21
3
votes
3 answers
In python exclude folders which start with underscore or more than six characters long
I want to store all the folder names except the folders which start with underscore (_) or have more than 6 characters.To get the list, i use this code
folders = [name for name in os.listdir(".") if os.path.isdir(name)]
What change do i need to…

Kneerudge
- 55
- 11
3
votes
3 answers
How to walk a directory over a local network using PHP?
How can i list the contents of a windows share using PHP?
$SearchFolder = "\\\\192.168.1.100\\pdfoutput\\";
if (is_dir($SearchFolder))
{
if ($Directory = opendir($SearchFolder))
{
while (($File = readdir($Directory)) !== false)
…

Gary Willoughby
- 50,926
- 41
- 133
- 199
2
votes
1 answer
Visit only directories of a specific depth with Java 7
When using the method
java.nio.file.Files.walkFileTree(Path root, Set options, int maxDepth, FileVisitor visitor)
one can specify the maximum depth of files to visit. Is there also a way to specify that only paths of a specific, exact depth shall…

oberlies
- 11,503
- 4
- 63
- 110