-- Directory creation script is fruity --
Hello Gang, while creating a simple loop to copy a directory
structure, I encountered a strange error
with os.path.join. In the loop below, only the first iteration of the
loop will join the new_dir with no_base.
After hours of research, I still cannot pin this one down. I have it
working at the bottom, but it does not feel as safe.
Has anyone seen this before?
original_dir = '/work/sites/templates'
new_dir = '/work/sites/copy_of_structure'
for (path, dirs, files) in os.walk(original_dir):
no_base = path.replace(original_dir, '')
new_path = os.path.join(new_dir, no_base)
self.stdout.write('path: %s \n' % new_path)
output:
path: /work/sites/copy_of_structure/
path: /gggg
path: /gggg/hdbklasj
should be:
path: /work/sites/copy_of_structure/
path: /work/sites/copy_of_structure/gggg
path: /work/sites/copy_of_structure/gggg/hdbklasj
HOWEVER:
This works just fine:
original_dir = '/work/sites/templates'
new_dir = '/work/sites/copy_of_structure'
for (path, dirs, files) in os.walk(original_dir):
no_base = path.replace(original_dir, 'new_dir')
self.stdout.write('path: %s \n' % new_path)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home