Skip to content
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

Using pathlib in code to simplify the code #15

Merged
merged 3 commits into from Apr 16, 2014
Merged

Using pathlib in code to simplify the code #15

merged 3 commits into from Apr 16, 2014

Conversation

lowks
Copy link
Collaborator

@lowks lowks commented Apr 16, 2014

Using pathlib in code to simplify the code. This is an okay lib to add as it's already accepted into Python-3.4 mainline, so later we don't really have to do any changes to migrate to it.

solos added a commit that referenced this pull request Apr 16, 2014
Using pathlib in code to simplify the code
@solos solos merged commit edba451 into solos:master Apr 16, 2014
@lowks
Copy link
Collaborator Author

lowks commented Apr 16, 2014

There is actually one more to this that I have not finished yet...

28def walktree(dirname, callback):                                                                                                    
29    '''recursively descend the directory tree rooted at top,                                                                        
30       calling the callback function for each regular file'''                                                                       
31                                                                                                                                    
32    for f in os.listdir(dirname):                                                                                                   
33        pathname = os.path.join(dirname, f)                                                                                         
34        mode = os.stat(pathname).st_mode                                                                                            
35        if stat.S_ISDIR(mode):                                                                                                      
36            # It's a directory, recurse into it                                                                                     
37            walktree(pathname, callback)                                                                                            
38        elif stat.S_ISREG(mode):                                                                                                    
39            # It's a file, call the callback function                                                                               
40            callback(pathname)                                                                                                      
41        else:                                                                                                                       
42            # Unknown file type, print a message                                                                                    
43            print 'Skipping %s' % pathname                                                                                          
44                                           

This one is a bit complicated, I am still looking at how to replace it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants