[Tutor] conditional renaming folder and files in the tree

banda gunda bandagunda at hotmail.com
Fri Aug 11 11:10:27 EDT 2017


Dear Tutor,

I want to change the name of the folders and the files in the tree.
All those folders and files starting with name string '---'.
Examples:
If a  folder name is : \---DAT1
I want to change this to: \changedDAT1
If a file name is: \---00001.txt
I want to change this to: \changed00001.txt

I have attached the code and output to this email.
Specifically, I like to provide correct syntax (dst / destination) for line 6 code block below!
I have not understood the syntax.

Thanks in advance, for your help .
best,
banda
+


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

    for name in dirs:
        print(os.path.join(root, name))


.\---DAT1\---00001.txt


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-b679212713d0> in <module>()
      2     for name in files:
      3         print(os.path.join(root, name))
----> 4         os.rename(name.replace("---", "changed"))
      5         list_of_files[name] = os.sep.join([dirpath, name])
      6         print (list_of_files)

TypeError: Required argument 'dst' (pos 2) not found

_end_of_email

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: file_folder_replace_name_strings.html
URL: <http://mail.python.org/pipermail/tutor/attachments/20170811/15282a5e/attachment-0001.ksh>


More information about the Tutor mailing list