我想创建一个脚本,该脚本读取带有带日期的子文件夹的文件夹,该日期将是我的.csv输出文件的第二个collun,我的第一个collun将是那些子文件夹中的.csv文件名,而我的输出文件第三个collun将是导入的.csv文件的第一个值减去最后一个。
import os
import csv
import datetime
path = r'P:\TV-443\Production Reports\Dosadores PTP\20190421'
for root, dirs, files in os.walk (path):
file_list =['<>']
for filename in files:
if filename .endswith ('.csv'):
file_list.append (os.path.join (root, filename))
#f_list = [pd.read_table (file) for file in file_list]
with open ('.csv', newline = '') as f:
reader = csv.reader (f)
a = firstvalue
def get_last_row (filePath):
with open (filePath, 'rb') as f:
return deque (csv.reader (f), 1)[0]
def main ():
a_str = int (firstvalue)
b_str = int ("deque (csv.reader (f), 1)[0]")
c_str = a_str - b_str
return thirdrow
main ()
def path_to_dict (path):
d = { 'name':os.path.basename (path)}
if os .path.isdir (path):
d['type'] = "directory"
d['children'] = [path_to_dict (os.path.join (path, x)) for x in os.listdir (path)]
#else: d['type'] = "file"
#return d
def parseCSV (filePath):
with open (filePath, 'rb') as csvfile:
blablabla = csv.reader (csvfile, delimiter = ';', quotechar =
'"')
for row in blablabla: print (row[1])
files = path_to_dict (path)
with path_to_dict (path) as csvfile:
newfile = filename
for row in blablabla:print (row[0])
newname = foldername
for row in blablabla: print (row[2])
#return secondrow
def writeCsv (data):
with open ("U:\teste.csv", "wb") as outfile:
writer = csv.writer (outfile)
filewriter.writerow (['Equipamento', 'Data','Valor'])
print(data)
print(files)
for file in files[' children ']:
parseCSV(path + ' \\ ' + file[' name '])