List all matlab files in python

3 views (last 30 days)
John on 3 Oct 2022
Commented: John on 5 Oct 2022
Hi. I need to convert the following matlab code to python:
DirList = dir(fullfile(Folder, '*.mat'));
Data = cell(1, length(DirList));
Do you have an idea of how to do it in python?
John on 4 Oct 2022
Yes, I want to list all the matlab files in python. Thank you for the help.

Sign in to comment.

Answers (1)

Al Danial
Al Danial on 4 Oct 2022
As @John mentioned, one way is with the glob function from the module of the same name:
from glob import glob
Dir = '.'
mat_files = glob(f'{Dir}/*.mat')
to create the Python list mat_files.
  1 Comment
John on 5 Oct 2022
Very helpful. Thank you!

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by