Python Forum
delete a file works but with error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
delete a file works but with error
#1
Hello,

I get an error from my code, I create the path in order to delete the correct file (I have import os of course), even if my code delete the correct file, in the terminal I get the following error:

ERROR WHILE DELETING THE FILE.

It doesn't write file deleted, but it deletes the file.

Why I get this error if the code delete the file anyway?


myfile = "test.png"
currentdir = os.getcwd()
path = currentdir + "/static/images/" + myfile

if os.path.exists(path):
    print("File deleted")
    os.remove(path)
else:
    print("ERROR WHILE DELETING THE FILE.")
Reply


Messages In This Thread
delete a file works but with error - by Leon79 - Jul-13-2020, 05:30 PM
RE: delete a file works but with error - by DPaul - Jul-13-2020, 05:31 PM
RE: delete a file works but with error - by Leon79 - Jul-13-2020, 06:35 PM
RE: delete a file works but with error - by DPaul - Jul-14-2020, 06:23 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete file with read-only permission, but write permission to parent folder cubei 6 22,465 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  DF.groupby(col).min works, mean gets a "not implemented" error samgardner5 3 866 Feb-29-2024, 06:13 PM
Last Post: deanhystad
  Delete multiple lines from txt file Lky 6 2,530 Jul-10-2022, 12:09 PM
Last Post: jefsummers
  Pandas - error when running Pycharm, but works on cmd line zxcv101 1 1,457 Jun-18-2022, 01:09 PM
Last Post: snippsat
  Find and delete above a certain line in text file cubangt 12 3,917 Mar-18-2022, 07:49 PM
Last Post: snippsat
  How to delete portion of file already processed? Mark17 13 3,042 Jan-22-2022, 09:24 AM
Last Post: Pedroski55
  Python Regular expression, small sample works but not on file Acernz 5 3,129 Jun-09-2021, 08:27 PM
Last Post: bowlofred
  Function throws error but then works? Milfredo 10 4,036 Sep-12-2020, 05:16 AM
Last Post: Milfredo
  Find, delete and add text into pdf file a_shvechkov 2 6,273 Jul-08-2020, 10:50 AM
Last Post: a_shvechkov
  Delete all contents of a file from the fifth line? PythonNPC 1 1,995 Apr-18-2020, 09:16 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020