Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: latin-1 -*-
- import os
- import sys
- import MySQLdb
- con = MySQLdb.connect('localhost','root','010203')
- con.select_db('arquivos')
- cursor = con.cursor()
- rootdir = u"D:\\ghostone"
- def Retrieve(dir):
- list = os.listdir(dir)
- filesIn=0
- for l in list:
- print l
- filename = l
- print filename
- size = os.path.getsize(os.path.join(dir,filename))
- modification = os.path.getmtime(os.path.join(dir,filename))
- creation = os.path.getctime(os.path.join(dir,filename))
- if os.path.isdir(os.path.join(dir,filename)):
- Retrieve(os.path.join(dir,filename))
- isfolder = 1
- else:
- isfolder = 0
- dir = dir.replace('\\','/');
- try:
- cursor.execute("INSERT INTO arquivos (nome, caminho, modificado, criado, tamanho, pasta) VALUES (%s,%s,%s,%s,%s,%s)", (filename, dir, modification, creation, size, isfolder))
- except MySQLdb.Error, e:
- print "Error %d: %s" % (e.args[0], e.args[1])
- #con.commit ()
- Retrieve(rootdir);
- cursor.close()
- con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement