SHARE
TWEET

Untitled

a guest Jul 24th, 2011 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top