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

Python os.walk(path) seems to be nice #40

Open
dominicparga opened this issue Feb 10, 2020 · 0 comments
Open

Python os.walk(path) seems to be nice #40

dominicparga opened this issue Feb 10, 2020 · 0 comments
Labels
documentation Some info, link, help, description
Projects

Comments

@dominicparga
Copy link
Owner

Add documentation

untested.
Unfortunately, copied from somewhere a few years ago..

import os

def createIndexFile(startpath, indexFile):
    for root, dirs, files in os.walk(startpath):
        files = [f for f in files if not f[0] == '.']
        dirs[:] = [d for d in dirs if not d[0] == '.']
        level = root.replace(startpath, '').count(os.sep) - 1
        indent = ' ' * 2 * (level)
        directory = os.path.basename(root)
        if directory != '.':
            indexFile.write('{}- {}\n'.format(indent, os.path.basename(root)))
            subindent = ' ' * 2 * (level + 1)
            for f in files:
                indexFile.write('{}- [{}]({})\n'.format(subindent, f[:-3], f[:-3]))

indexFile = open('_Sidebar.md', 'w')
createIndexFile(".", indexFile)
indexFile.close()
@dominicparga dominicparga added the documentation Some info, link, help, description label Feb 10, 2020
@dominicparga dominicparga added this to Backlog in Python Feb 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Some info, link, help, description
Projects
Python
  
Backlog
Development

No branches or pull requests

1 participant