directory-walk

What is the Python way to walk a directory tree?

£可爱£侵袭症+ 提交于 2019-11-27 23:04:13
问题 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 回答1: Take a look at the os.walk function which returns the path along with the directories and files it contains. That

Is there a workaround for Java's poor performance on walking huge directories?

和自甴很熟 提交于 2019-11-27 13:15:50
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 folders. Performance is super slow since File.list() returns an array instead of an iterable. Java goes off and collects all the names in a folder and packs it into an array before returning. The bug entry for this is http://bugs.sun.com/view_bug.do;jsessionid=db7fcf25bcce13541c4289edeb4?bug_id=4285834 and doesn't have a work around. They just say

Is there a workaround for Java's poor performance on walking huge directories?

老子叫甜甜 提交于 2019-11-26 16:16:14
问题 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 folders. Performance is super slow since File.list() returns an array instead of an iterable. Java goes off and collects all the names in a folder and packs it into an array before returning. The bug entry for this is http://bugs.sun.com/view_bug.do