0

This a a portion of a larger code.

I have a directory with 100's of .log files that I need to convert to .xlsx files one at a time. I wrote this code;

import csv
import glob
import pandas as pd

df = pd.read_csv('input.log', delimiter=r"\s+", header=None, names=list(range(20)))
df.to_excel('input.xlsx', 'Sheet1')

Which works for a single file. What do I need to add to have it look through the directory and convert each file regardless of how many there are?

1 Answers1

0
import glob
import pandas as pd

files = glob.glob("*.log")

for file in files:
    df = pd.read_csv(file, delimiter=r"\s+", header=None, names=list(range(20)))
    df.to_excel(file+'.xlsx', index=Flase)
Mo Huss
  • 434
  • 2
  • 11