190510
コンピューター:C言語講座:ディレクトリ内容の読み出し
http://www.ncad.co.jp/~komata/c-kouza14.htm
-----
update staff set name = 'Nakajima' where id = 3
①作成
CREATE TABLE musics(fullpath PRIMARY KEY, mdata ,title,artist,alubumartist,alubum,date,check);
②更新チェック
チェックカラムをクリア
update musics set check = 0 # no where --> all
p # iterate filename
os.path.getmdata(p)
SELECT fullpath ,mdata FROM musics WHERE fullpath=p
if fetchone() :
取り出せれば mdataを比較 同じならパス
違ったらUPDAte
else
取り出せなければインサート
チェックを1に更新
最後にチェック0があればデータ削除
count={'all':0 , 'dir':0 , 'mfile':0 , 'ofile':0}
count['all']+=1
import glob ,re , os
import sqlite3
import time
# ファイルの更新日時に変更等があればチェック
# データベース作成済み(ファイル名、mtime のみ)
count={'all':0 , 'file':0 , 'same':0 , 'diff':0 ,'none':0 , 'new':0}
conn = sqlite3.connect( <pas>)
c = conn.cursor()
c.execute('create table IF NOT EXISTS musics(fullpath PRIMARY KEY, mtime ,title,alubum)')
fo=r'i:\Music\jazz\**'
sel='select mtime from musics where fullpath = ?'
start = time.time()
for p in glob.iglob(fo , recursive=True):
count['all']+=1
if os.path.isfile(p):
count['file']+=1
nmtime=os.path.getmtime(p)
c.execute(sel,(p,))
res=c.fetchone()
if res :
if res[0]==nmtime :
count['same']+=1
else :
count['diff']+=1
print(p)
else:
count['new']+=1
print(p)
elapsed_time = time.time() - start
print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")
c.execute('select count (*) from musics')
print('data--{0}'.format(c.fetchall()))
print(count)
conn.close()