from os import walk
from os.path import getsize
from os.path import getmtime
from datetime import datetime
from os import chdir
chdir(path)
resultFile = 'result.csv'
for (path, dir, files) in walk('.'):
for filename in files:
ext = filename.split('.')[-1]
size = getsize(path + '\\' + filename)
mtime = str(datetime.fromtimestamp(getmtime(path + '\\' + filename)))[:19]
lst = '#'.join([ path, filename, ext, str(size), str(mtime)+'\n' ])
with open(resultFile, 'a') as f:
f.writelines(lst)
import pandas as pd
import numpy as np
from datetime import datetime
from elasticsearch.helpers import bulk
from elasticsearch import Elasticsearch
es = Elasticsearch(hosts=' ',port=' ', timeout=600)
ix = 'filelist'
es.indices.create(index=ix)
data = pd.read_csv(filename
, engine='python'
, sep='#'
, header=None
, names=['path', 'filename', 'ext', 'size','mtime'])
data['mtime'] = pd.to_datetime(data['mtime'], format='%Y-%m-%d %H:%M:%S')
data['size'] = data['size'].astype(np.int)
documents = data.to_dict(orient='records')
bulk(es, documents, index=ix, doc_type='_doc')