I want to delete top and bottom lines in multiple csv files in a folder at once. Then delete the second line after that. My code works well with one file but i have 1000s of files to go through and i cannot specify each file name. How can i modify this to make it work?
#Remove top and bottom lines from all files
lines = open('My/local/Drive/*.csv').readlines()
open('My/local/Drive/*.csv', 'w').writelines(lines[2:-4]);
#Remove 2nd line from all files
lines = []
with open('My/local/Drive/*.csv', 'r') as f:
lines = f.readlines()
with open('My/local/Drive/*.csv', 'w') as f:
f.writelines(lines[:1] + lines[2:]);