Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Python. Write an algorithm for the following question. Write a program that a

ID: 3852647 • Letter: I

Question

In Python.

Write an algorithm for the following question.

Write a program that asks the user for a path to a directory, and then updates the names of all the files in the directory that have the word draft to instead say final

EX: "term paper (draft).txt" would be renamed "term paper (final).txt"

BONUS (5pts): for any .txt file that your program changes the name of, have your program add a line of text that states "Edited on " followed by the current date to the end of the text in the file that it is editing.

Explanation / Answer

import glob, os
import fnmatch
def rename(dir, name,newName):
for filename in os.listdir(dir): #opening file names
       if fnmatch.fnmatch(filename, name): #matching file names
           os.rename(filename, newName) # renaming file names
              
rename(r'c: empmyFolder', 'draft', 'final')                  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote