import tkinter as tk
from ftplib import FTP
pencere = tk.Tk()
pencere.title("Title")
pencere.geometry("800x300")
def deleteAllFiles(ftp):
for n in ftp.nlst():
try:
if n not in ('.','..'):
print('Working on..'+n)
try:
ftp.delete(n)
print('Deleted...'+n)
except Exception:
print(n+' Not deleted, we suspect its a directory, changing to '+n)
ftp.cwd(n)
deleteAllFiles(ftp)
ftp.cwd('..')
print('Trying to remove directory ..'+n)
ftp.rmd(n)
print('Directory, '+n+' Removed')
except Exception:
print( 'Trying to remove directory ..'+n)
ftp.rmd(n)
print('Directory, '+n+' Removed')
ftp = FTP('***')
username="**"
pwd="**"
ftp.login(username, pwd)
ftp.cwd('htdocs')
deleteAllFiles(ftp)
print('Done deleting all Files and Directories')
etiket = tk.Label(text="LABEL" ,font = "Verdana 22 bold")
etiket.pack()
button1=tk.Button(pencere, text="Button", command=deleteAllFiles(ftp))
button1.pack()
button2=tk.Button(pencere, text="Quit", command=pencere.quit)
button2.pack()
pencere.mainloop()
This code helps to delete the files in the folder I specified via ftp, but I start the application and apply the command without pressing the button.
running deleteAllFiles(ftp) command without clicking button how can i solve this
current code;
import tkinter as tk
from ftplib import FTP
pencere = tk.Tk()
pencere.title("Title")
pencere.geometry("800x300")
def deleteAllFiles(ftp):
for n in ftp.nlst():
try:
if n not in ('.','..'):
print('Working on..'+n)
try:
ftp.delete(n)
print('Deleted...'+n)
except Exception:
print(n+' Not deleted, we suspect its a directory, changing to '+n)
ftp.cwd(n)
deleteAllFiles(ftp)
ftp.cwd('..')
print('Trying to remove directory ..'+n)
ftp.rmd(n)
print('Directory, '+n+' Removed')
except Exception:
print( 'Trying to remove directory ..'+n)
ftp.rmd(n)
print('Directory, '+n+' Removed')
ftp = FTP('@@')
username="@@"
pwd="@@"
ftp.login(username, pwd)
ftp.cwd('htdocs')
#deleteAllFiles(ftp)
print('Done deleting all Files and Directories')
button1=tk.Button(pencere, text="Button", command=lambda: deleteAllFiles(ftp))
button1.pack()
etiket = tk.Label(text="LABEL" ,font = "Verdana 22 bold")
etiket.pack()
button2=tk.Button(pencere, text="Button", command=pencere.quit)
button2.pack()
pencere.mainloop()
this is current code still same command running automatically @Matiiss what can i do please help (I need to write a little more, so I'm writing)