Copy directory tree without copying files

Jeremy Conlin jlconlin at gmail.com
Wed Sep 23 11:25:55 EDT 2009


On Sep 23, 9:15 am, dwatrous <daniel.watr... at gmail.com> wrote:
> Have you considered using os.walk?http://docs.python.org/library/os.html#os.walk
>
> It won't be completely automated, but I think it should allow you to
> easily walk the directory structure to reproduce it in another
> location.
>
> If the file names/extensions are predictable you might also be able to
> use the ignore attribute in the shutil.copytree function to prevent
> copying files:http://docs.python.org/library/shutil.html#shutil.copytree
>
> Daniel
>

Thanks, that helps.  I could write a function like

def ignore_files(dirpath):
    ignore = []
    for f in os.listdir(dirpath)
        if os.path.isfile(f):
            ignore.append(f)
    return ignore


That seems like it will work (haven't tested yet).  Thanks for the
help.
Jeremy





More information about the Python-list mailing list