Deleting and renaming files

 Two other useful functions when working with files are the remove() and rename() functions. These functions are available in the os module and have to be imported before use.


The remove() function deletes a file. The syntax is remove(filename). Example: remove('woohoo.txt')


The rename() function renames a file. The syntax is rename(old name, new name). Example: rename('woohoo.txt', 'hooray.txt')

No comments:

Post a Comment