Hello so I am getting this error permission denied when I run this python script.
import os
keyword = input("Enter Keyword to search : ")
replacement = input("Enter replacement string : ")
for filename in os.listdir():
with open(os.path.join(os.getcwd(), filename), 'r') as f: # open in readonly mode
content = f.read()
if keyword in content:
with open(os.path.join(os.getcwd(), filename), 'w') as fw: # open in write mode
writecontent = content.replace(keyword, replacement)
fw.write(writecontent)
print(f"Keyword {keyword} found and replaced in file : {filename}")
input("Press Enter to exit")
the error I am getting is
Traceback (most recent call last):
File "c:/Users/smraf/Desktop/Test Python/script.py", line 9, in <module>
with open(os.path.join(os.getcwd(), filename), 'r') as f:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\username\\Desktop\\Test Python\\.vscode'
The problem is when I run this on a different laptop it works. My coworker tried running it on theirs and it doesn't work either so I am not sure why it's giving me this error.