Reputation: 11
I have to convert .las
files in one directory to .xlsx
files using las2excelbulk
function.
Currently I can do that in command prompt but I want to do it using Python: is it possible?
Here's the link which i referred https://lasio.readthedocs.io/en/latest/exporting.html
Open CMD
switch to the folder having las files using " cd
las2excelbulk -r -i
The file would be converted.
# this is working for only one file
import lasio
las = lasio.read('*.las')
las.to_excel('testsamplelas.xlsx')
Upvotes: 1
Views: 1221
Reputation: 497
The argument to lasio.read()
can only be a single filename, but you can use the os
and fnmatch
modules in the Python standard library to step through all .las files recursively.
import fnmatch
import os
import lasio
for root, dirnames, filenames in os.walk("your_directory"):
for filename in fnmatch.filter(filenames, '*.las'):
path = os.path.join(root, filename)
las = lasio.read(path, ignore_header_errors=True)
las.to_excel(path + ".xlsx")
lasio.read(..., ignore_header_errors=True)
is the equivalent of las2excelbulk -i
.
It may also be useful to inspect the code behind the las2excelbulk
command line tool for more information.
Upvotes: 2