I created the two .py files, the two .txt files and the to_traverse/ directory for this assignment, but I’m getting stuck on moving the .txt files into the to_traverse directory using code. I tried using both the os.rename() and the shutil.move() methods as follows:
When I don’t wrap the file paths in quotes, python throws me the following error: NameError: name ‘practicing_file_writing’ is not defined. When I wrap them in quotes, python throws me a different error: FileNotFoundError: [Errno 2] No such file or directory ‘practicing_file_writing.txt’. Could you explain briefly (I know you’re busy and have limited time for newbies!) how you’re supposed to use these methods?
I created the two .py files, the two .txt files and the to_traverse/ directory for this assignment, but I’m getting stuck on moving the .txt files into the to_traverse directory using code. I tried using both the os.rename() and the shutil.move() methods as follows:
os.rename(home/jmacula/practicing_file_writing.txt,home/jmacula/to_traverse/practicing_file_writing.txt)
os.rename(“home/jmacula/practicing_file_writing.txt”,“home/jmacula/to_traverse/practicing_file_writing.txt”)
shutil.move(home/jmacula/practicing_file_writing.txt,home/jmacula/to_traverse/practicing_file_writing.txt)
shutil.move(“home/jmacula/practicing_file_writing.txt”,“home/jmacula/to_traverse/practicing_file_writing.txt”)
When I don’t wrap the file paths in quotes, python throws me the following error: NameError: name ‘practicing_file_writing’ is not defined. When I wrap them in quotes, python throws me a different error: FileNotFoundError: [Errno 2] No such file or directory ‘practicing_file_writing.txt’. Could you explain briefly (I know you’re busy and have limited time for newbies!) how you’re supposed to use these methods?