[Tutor] conditional renaming folder and files in the tree

Alan Gauld alan.gauld at yahoo.co.uk
Sat Aug 12 03:51:51 EDT 2017


On 11/08/17 16:10, banda gunda wrote:

> for root, dirs, files in os.walk(".", topdown=False):
>     for name in files:
>         print(os.path.join(root, name))
>         os.rename(name.replace("---", "changed"))

Here you give the new name but not the original name.
The function needs two values, the source(original name)
and the destination(dst)


>         list_of_files[name] = os.sep.join([dirpath, name])

What is dirpath? This is its first mention.

> ---------------------------------------------------------------------------
> TypeError                                 Traceback (most recent call last)
> <ipython-input-6-b679212713d0> in <module>()
> ----> 4         os.rename(name.replace("---", "changed"))
> 
> TypeError: Required argument 'dst' (pos 2) not found

See above

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list