Reading all .csv files with different names

  • Context: MATLAB 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    files Reading
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 2K views
member 428835
Hi PF!

I am trying to read all the .csv files in a folder. When I execute
Code:
OFdata  = readtable('/home/josh/Documents/NASA/PSI_DATA/Double_Drain/ICF1-9/OpenFOAM_DATA/*.csv');
I get a general error. However, replacing the asterisk with the file name, it load no issue.

I've seen online how to read several .csv files with only a numeric difference in name (for loops), but is there a way to read all .csv files with different names?
 
Last edited by a moderator:
Physics news on Phys.org
dir() calls the Linux OS - which globs the filenames it can find with the pattern: "*.csv". Then dir() executes stat() to get attributes -- on each file it finds. Like filetimes, file ownership, etc. - you can ask it do lots of tricks.

You can see the the one call python asks Linux to make for mulitiple objects. when you read the man page for glob. It works on filesystems and file, not what are categorized as python __dict__ objects.

From bash -- dir() is a window-ism for ls:
Code:
man glob
Code:
man ls

Most of the Linux OS is written in the C language, so part of the glob page shows how call it in your own C program. And explains lots details.

python acts as an intermediate for you.

But this is why I mentioned to you earlier about learning UNIX or Linux. Anytime an intermediate (interpreted usually) app does some OS good thing for you, you can control it better when you understand how something works underneath.

... followup from our earlier conversation.
 
  • Like
Likes   Reactions: member 428835
Thank you both! Very helpful, and Jim, I'm working on getting better with Linux. Starting with some simple shell scripts, baby steps.