directory-walk

How to walk through directory tree step by step?

我只是一个虾纸丫 提交于 2020-01-13 05:49:07
问题 I found many examples on walking through directory tree, but I need something a little different. I need a class with some method which each call returns one file from directory and gradually walking through directory tree. How can I do this please? I am using functions FindFirstFile, FindNextFile and FindClose, I am newbie in c++. I have something like this... For example I have this simple directory tree Parent(folder)\ file1.txt file2.txt Child(folder)\ file3.txt file4.txt and I need a

Quicker to os.walk or glob?

夙愿已清 提交于 2019-12-31 08:28:53
问题 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 them both and could say which is more efficient? As I say, glob seems to be slower, but you can use wildcards etc, were as with walk, you have to filter results. Here is an example of looking up core dumps. core = re.compile(r"core\.\d*") for root, dirs

Can I make RecursiveDirectoryIterator skip unreadable directories?

情到浓时终转凉″ 提交于 2019-12-21 03:31:23
问题 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 subdirectory inside directory I attempt to list? UPDATE Converting foreach() to while() and explicitly calling Iterator::next() wrapped in try() catch {} doesn't help. This code: $iter = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(".")

unable to skip unreadable directories with RecursiveDirectoryIterator

泄露秘密 提交于 2019-12-08 16:00:55
问题 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 RecursiveDirectoryIterator skip unreadable directories? however my code is slightly different here and I am not able to get around the problem. $path = 'www/'; foreach (new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path,RecursiveDirectoryIterator::KEY

How to walk through directory tree step by step?

天大地大妈咪最大 提交于 2019-12-04 17:07:12
I found many examples on walking through directory tree, but I need something a little different. I need a class with some method which each call returns one file from directory and gradually walking through directory tree. How can I do this please? I am using functions FindFirstFile, FindNextFile and FindClose, I am newbie in c++. I have something like this... For example I have this simple directory tree Parent(folder)\ file1.txt file2.txt Child(folder)\ file3.txt file4.txt and I need a class with a method for example getNextFile(), that first call returns file1.txt; second call returns

Hadoop MapReduce provide nested directories as job input

六月ゝ 毕业季﹏ 提交于 2019-12-03 11:53:40
问题 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 one/ as an input path, no files are processed, since none are immediately available at the root level. I read about job.addInputPathRecursively(..) , but this seems to have been deprecated in the more recent releases (I'm using hadoop 1.0.2). I've written some code to walk the

A Python walker that can ignore directories

随声附和 提交于 2019-12-03 07:04:27
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. Actually, os.walk may do exactly what you want. Say I have a list (perhaps a set) of directories to ignore in ignore . Then this should work: def my_walk(top_dir, ignore): for dirpath, dirnames, filenames in os.walk(top_dir): dirnames[:] = [ dn for dn in dirnames if os.path.join(dirpath, dn) not in ignore ] yield dirpath, dirnames, filenames It is possible to modify the second element of

Hadoop MapReduce provide nested directories as job input

为君一笑 提交于 2019-12-03 01:23:33
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 one/ as an input path, no files are processed, since none are immediately available at the root level. I read about job.addInputPathRecursively(..) , but this seems to have been deprecated in the more recent releases (I'm using hadoop 1.0.2). I've written some code to walk the folders and add each dir with job.addInputPath(dir) , which worked until the job crashed when trying to

Quicker to os.walk or glob?

这一生的挚爱 提交于 2019-12-02 17:40:56
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 them both and could say which is more efficient? As I say, glob seems to be slower, but you can use wildcards etc, were as with walk, you have to filter results. Here is an example of looking up core dumps. core = re.compile(r"core\.\d*") for root, dirs, files in os.walk("/path/to/dir/") for file in files: if core.search(file): path = os.path.join(root

What is the Python way to walk a directory tree?

会有一股神秘感。 提交于 2019-11-29 05:29:37
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 = [] for i, item in enumerate(contents): if isfile(contents[i]): files += [item] elif isdir(contents[i]): folders += [item] return files, folders Sanjay T. Sharma Take a look at the os.walk function which returns the path along with the directories and files it contains. That should considerably shorten your solution. Indeed using items += [item] is bad for many