I can find my file with this code that I made, but I can't unlink my file as an error shows up that it cant find("my_filename.rxt") can somebody help me with this?
import os
for foldername, subfolders, filenames in os.walk("h:"):
for subfolder in subfolders:
for filename in filenames:
if filename.endswith(".rxt"):
print(filename)
os.unlink(filename)
thanks. I was able to do this program with this.
import os
def recursive_unlink(dirname):
for entry in os.scandir(dirname):
if entry.is_dir():
recursive_unlink(os.path.abspath(entry))
elif entry.name.endswith('.rxt'):
os.unlink(os.path.abspath(entry))
recursive_unlink('h:\desktop')
but when I tried to find a text in the files and delete files with certain texts in them, I couldn't. could someone help me again?
import os
def recursive_unlink(dirname):
for entry in os.scandir(dirname):
if entry.is_dir():
recursive_unlink(os.path.abspath(entry))
elif entry.name.endswith('.rxt'):
file = os.path.join(foldername,filename)
file = open(file, 'r')
phrase = findWholeWord('MZ・ ク @ コ エ ヘ!クLヘ!This program cannot be run in DOS mode.')(file)
if phrase == True
os.unlink(os.path.abspath(file))
recursive_unlink('h:\\desktop')