I am struggling to write a for loop to convert approximately 100 `.dat` files into `.csv`.

My `.dat` files look like this:

```
% Filename : Spm04A1_00288_00001.tif
% Date & Time : 26-Oct-2021 15:45:01
% X-ray Energy (keV) : 20.000
% Exposure Time (s) : 1.030
% Beam Center : 718.20700, 1572.10000
% Sample to Detector Distance (SDD) (mm) : 2175.520
% Detector Pixel Size (mm) : 0.146
% Photodiode Value : 176453.000
% 10 of Sample : 198187
% 10 of Standard : 1
% q(A^-1) I(q) sqrt(I(q))
0.00000000e+00    0.00000000e+00    0.00000000e+00
6.78047596e-04    0.00000000e+00    0.00000000e+00
1.35609519e-03    0.00000000e+00    0.00000000e+00
2.03414279e-03    0.00000000e+00    0.00000000e+00
2.71219038e-03    0.00000000e+00    0.00000000e+00
3.39023798e-03    0.00000000e+00    0.00000000e+00
4.06828558e-03    0.00000000e+00    0.00000000e+00
4.74633317e-03    0.00000000e+00    0.00000000e+00
5.42438077e-03    0.00000000e+00    0.00000000e+00
6.10242836e-03    0.00000000e+00    0.00000000e+00
6.78047596e-03    0.00000000e+00    0.00000000e+00
7.45852356e-03    0.00000000e+00    0.00000000e+00
8.13657115e-03    0.00000000e+00    0.00000000e+00
8.81461875e-03    9.12221748e+00    3.23146137e+00
9.49266634e-03    8.47547513e+00    1.27051027e+00

```

The data files consist of X-ray scattering data with three columns (`scattering vector`, `intensity`, and `sqrt(intensity)`. They are the raw data files that were received from a recent scattering trip. In order to process these data files in a different piece of software, I need to convert them into `.csv`.

I was able to edit one file (and add headers) using this code:

```py
headerList = ['q(A^-1)', 'I(q)', 'sqrt(I(q))']

data.to_csv("Spm04A3_00258_00001.csv", header=headerList, index=False)

data2 = pd.read_csv("Spm04A3_00258_00001.csv")
print('\nModified file:')
print(data2)

```

Unfortunately, that is not efficient for converting 100 data files but I really struggle with writing loops. I would appreciate any suggestions.