-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement walkdir. fixes #8814 #13707
Conversation
Years after we first argued about adding a function to do this, I hope we can add this one. |
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw) | ||
|
||
The walkdir method return an iterator that walks the directory tree of a directory. The iterator returns a tuple containing | ||
`(rootpath, dirs, files)`. The directory tree can be transversed top-down and bottom-up. If walkdir encounters a SystemError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
traversed top-down or bottom-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@tkelman I have addressed the comments and force pushed a new version. |
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw) | ||
|
||
The walkdir method return an iterator that walks the directory tree of a directory. The iterator returns a tuple containing | ||
`(rootpath, dirs, files)`. The directory tree can be transversed top-down or bottom-up. If walkdir encounters a SystemError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missed a typo, traversed not transversed
This is really nicely done and well tested, so +1 from me. It'll either have to be exported from Base or qualified in the tests. If it gets exported, then a signature for it should be added in the RST stdlib docs so |
504281b
to
af2f650
Compare
I have now exported it from Base. How should I add it to RST stdlib docs, any good examples? |
The process is described at https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#improving-documentation, sorry it's slightly messy at the moment. Take a look at https://raw.githubusercontent.com/JuliaLang/julia/master/doc/stdlib/file.rst, I think what you have to do is populate just the first |
Ok. I have possibly found a good way to test the |
eeba237
to
a9780eb
Compare
I have added test for the My Ubuntu cannot build due to an openssl error while building dependencies. I will see if I can figure it out, but it will not be before Sunday. |
apt-get install libssl-dev What's the justification for ignoring errors by default? What kind of scenarios would cause errors? I don't like the sound of ignoring errors by default, but how often would errors be expected? |
@test files == ["file_dir2"] | ||
|
||
end | ||
@unix_only rm(dirwalk, recursive=true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't merge like this, cleanup is necessary on windows too
The default is to throw all errors, if you pass a different function to onerrors it applies that to the error (if it's a SystemError), if it's not a SystemError it raises no matter what. I'm not a huge fan of that API however, I think a Boolean (or even a String) to throw/suppress errors would be better than passing around a function - that's the python API but it seems a little un-julian. |
The
Errors will occur if the user move directories or change the current working directory while using a relative path to the root directory while iterating
The API is made with a function because then the user could make some kind of handling of the missing dir. Python's edit: |
Utopic is 14.10, right? I think that went end-of-life a few months ago: http://fridge.ubuntu.com/2015/07/03/ubuntu-14-10-utopic-unicorn-reaches-end-of-life-on-july-23-2015/ so you probably need to The handling callback seems okay to me and more flexible than a boolean flag. Though moving files around during |
I have executed |
30,000th travis build passed! |
This seems useful also for 0.4, is there any chance of a backport? |
I'd rather avoid backporting new features in most cases, especially not without being proven on master for some time. This is a pretty small amount of pure julia code and could easily be put in a package, even Compat.jl, for use on 0.4 and even 0.3. |
Putting it in Compat is the right way to go. As a policy, we don't backport features. |
This implements a
walkdir
function equivalent to Python'sos.walk
. I have added test for the function and it's keyword arguments. Please correct the docs, as I am not a native speaker. My only remaining question is whetherwalkdir
should do asos.walk
and swallow errors as default.Fixes #8814