Sunday, July 14, 2013

Simple GUI python to delete file and its link

#!/usr/bin/python

from Tkinter import *
import os
import re

def cipher():
    data = text_area.get("1.0",END)

    As,Ts,Cs,Gs, = 0,0,0,0

    for x in data:
        if 'A' == x:
            As+=1
        elif x == 'T':
            Ts+=1
        elif x =='C':
            Cs+=1
        elif x == 'G':
            Gs+=1
    #result.set('Num As: '+str(As)+' Num of Ts: '+str(Ts)+' Num Cs: '+str(Cs)+' Num Gs: '+str(Gs))s
    data = re.sub('\n','', data)
  
    resultarray = []
  
    if os.path.exists(data):
    resultarray.append("file existed :" + data)
    #link = os.readlink(data)
    if os.path.islink(data):
        link = os.readlink(data)
        resultarray.append("link existed :" + link)
        try:
             os.remove(link)
                        resultarray.append("deleted")
            except:
                    resultarray.append("delete fail")
    try:
        os.remove(data)
        resultarray.append("deleted")
    except:
        resultarray.append("delete fail")
    else:
        resultarray.append("link not existed :" + data)
    else:
    resultarray.append("file not existed :" + data)
      

  
  
    result.set("\n".join(resultarray))
  

window = Tk()

#frame=Frame(window)
#frame.pack()

text_area = Text(height=2)
text_area.pack()

result = StringVar()
result.set('Input file path to delete')
label=Label(window,textvariable=result)
label.pack()

button=Button(window,text="Delete", command=cipher)
button.pack()
window.mainloop()

No comments:

Post a Comment