Advertisement
Guest User

Untitled

a guest
Jul 24th, 2011
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. # -*- coding: latin-1 -*-
  2. import os
  3. import sys
  4. import MySQLdb
  5.  
  6. con = MySQLdb.connect('localhost','root','010203')
  7. con.select_db('arquivos')
  8. cursor = con.cursor()
  9.  
  10.  
  11. rootdir = u"D:\\ghostone"
  12.  
  13. def Retrieve(dir):
  14.     list = os.listdir(dir)
  15.     filesIn=0
  16.     for l in list:
  17.         print l
  18.         filename = l
  19.         print filename
  20.         size = os.path.getsize(os.path.join(dir,filename))
  21.         modification = os.path.getmtime(os.path.join(dir,filename))
  22.         creation = os.path.getctime(os.path.join(dir,filename))
  23.         if os.path.isdir(os.path.join(dir,filename)):
  24.             Retrieve(os.path.join(dir,filename))
  25.             isfolder = 1
  26.         else:
  27.             isfolder = 0
  28.         dir = dir.replace('\\','/');
  29.         try:
  30.             cursor.execute("INSERT INTO arquivos (nome, caminho, modificado, criado, tamanho, pasta) VALUES (%s,%s,%s,%s,%s,%s)", (filename, dir, modification, creation, size, isfolder))
  31.         except MySQLdb.Error, e:
  32.             print "Error %d: %s" % (e.args[0], e.args[1])
  33.         #con.commit ()
  34.  
  35.        
  36. Retrieve(rootdir);
  37. cursor.close()
  38. con.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement