import sqlite3
import os
import shutil
conn = sqlite3.connect('database.db')
c = conn.cursor()
uname = input("Enter your name: ")
c.execute("DELETE FROM users WHERE id=(?)",(uname,))
if os.path.exists("./dataset"):
os.remove("./dataset/"+uname+".*"+".*"+".jpg")
else:
print("not exists, please check your id")
This part is confusing In the current dataset folder, kkk.1.1.jpg kkk.1.2.jpg...kkk.2.49.jpg kkk.2.50.jpg
The file name is in this format. So I want to delete all the image files called kkk
It's stuck at the top of the code. Please coach this part
conn.commit()
conn.close()
Enter your name: kkk
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-15-e43c10ee2457> in <module>()
18
19 if os.path.exists("./dataset"):
---> 20 os.remove("./dataset/"+uname+ ".* "+" .* "+".jpg")
21 else:
22 print("not exists, please check your id")
FileNotFoundError: [Errno2] No such file or directory: './dataset/kk. *.jpg'
Currently, an error appears like this.
python delete image
The system() function enables you to use the shell as if you were deleting a file with the rm command.
// Enter your code here
import os
os.system('rm ' + './dataset/' + uname + '*' + '.jpg')
© 2024 OneMinuteCode. All rights reserved.