Get of files containing filenames only from a given directory

Debdatta_Sen
Debdatta_Sen
Altair Employee
edited October 2020 in Community Q&A

Hi,

 

Let's say I am in directory C:\Test
This directory contains many different files including some H3D Files.
I want to create a list containing the names of these files only.

What is the best way to go about it?

Using 'ls' or 'system' can be used with the wildcards, but returns a lot of unwanted information as a string.
It is not very eays to filter this output.

 

I am looking for a command similar to 'glob' in TCL.

All I want is a list of files containing a specific extension to be returned.

Tagged:

Answers

  • robertavarela
    robertavarela New Altair Community Member
    edited February 2020

    If you are already in the directory where you should look for the H3D files, you may use the function dir followed by .h3d extension:

         myfiles = dir('*.h3d')

    It will return a list of .h3d files.

         length(myfiles) --> total number of .h3d files

         myfiles(i).name --> access to the .h3d file name according to the index i, which ranges from 1 to the number of files

    And other details about these files are also available, such as date of creation, size etc.

    Regards