-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrip_file_headers_multiple_file.py
More file actions
42 lines (25 loc) · 986 Bytes
/
strip_file_headers_multiple_file.py
File metadata and controls
42 lines (25 loc) · 986 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Batch File Header Stripper.
This script performs an in-place modification of all files located within a
specified directory ('raw_data'). It iterates through each file, reads its
contents while skipping the first two lines, and then overwrites the original
file with the remaining content.
This is primarily used for preprocessing raw data files to remove fixed-size
headers before further analysis or import into other programs.
**WARNING:** This is a destructive operation. It permanently modifies the files
in the target directory. It is highly recommended to back up the original
data before running this script.
"""
import pandas as pd
import numpy
import os
import re
directory = 'raw_data'
for filename in os.scandir(directory):
if filename.is_file():
with open(filename,'r') as f:
f.readline()
f.readline()
f_content=f.read()
with open(filename,'w') as f1:
f1.write(f_content)