On 06/03/2013 07:45, Νίκος Γκρ33κ wrote:
I'am using this snipper to read a current directory and insert all filenames 
into a databse and then display them.

But what happens when files are get removed form the directory?
The inserted records into databse remain.
How can i update  the databse to only contain the existing filenames without 
losing the previous stored data?

Here is what i ahve so far:

==================================
path = "/home/nikos/public_html/data/files/"

#read the containing folder and insert new filenames
for result in os.walk(path):

You were told yesterday at least twice that os.walk returns a tuple but you still insist on refusing to take any notice of our replies when it suits you, preferring instead to waste everbody's time with these questions. Or are you trying to get into the Guinness Book of World Records for the laziest bastard on the planet?

        for filename in result[2]:
                try:
                        #find the needed counter for the page URL
                        cur.execute('''SELECT URL FROM files WHERE URL = %s''', 
(filename,) )
                        data = cur.fetchone()        #URL is unique, so should 
only be one
                        
                        if not data:
                                #first time for file; primary key is automatic, 
hit is defaulted
                                cur.execute('''INSERT INTO files (URL, host, 
lastvisit) VALUES (%s, %s, %s)''', (filename, host, date) )
                except MySQLdb.Error, e:
                        print ( "Query Error: ", 
sys.exc_info()[1].excepinfo()[2] )
======================

Thank you.


--
Cheers.

Mark Lawrence

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to