0

Here's the code

    import os
    while True:
        print "Upisite ime datoteke koju zelite izbrisati"
        izbrisi = os.remove(raw_input(""))

So I run this program in attempt to delete file but that file that doesn't exist so it just closes the program even its in while loop(when file does exist loop continiues). I tried with if statement but I couldn't make it work.

Cager
  • 13
  • 2
  • @ TigerhawkT3 I could not find that question/thread. I was trying with google for 20 min but couldn't find anything. – Cager Mar 04 '17 at 23:22

1 Answers1

1

you could try:

import os
while True:
    print "Upisite ime datoteke koju zelite izbrisati"
    try:
        fname = raw_input("")
        izbrisi = os.remove(fname)
    except OSError as err:
        print "failed to remove %s" % fname
        pass #ignore the exception
ewcz
  • 12,819
  • 1
  • 25
  • 47