How to find the name of a file from a folder?

조회 수: 109 (최근 30일)
faran
faran 2016년 12월 6일
댓글: Alikouider 2022년 1월 28일
Hi, I have a folder containing 1 hidden file and 10 images which are '.DS_Store 01 02 03 04 05 ... 09 10'. When I'm reading all the files from the folder it will read the hidden file too. I want to have the name of the hidden file, how can I do it? I used the "dir" command to read the names only but since the MAC is not updated it will not read anything. Is there any other command to read only names of the files in a folder? this is the program I used:
folderpath='/Users/faranak/Desktop'; folderpath=strcat(folderpath,[filesep '/**/' filesep]); filelist=dir(folderpath); filelist.name %%% which gives me the names of the files
  댓글 수: 1
Jan
Jan 2016년 12월 6일
Why does the update status of the OS prevent the dir command to reply file names?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2016년 12월 6일
folderpath = '/Users/faranak/Desktop';
folderpath = fullfile(folderpath, '**'); % What is the meaning of "/**/" ???
filelist = dir(folderpath);
name = {filelist.name};
name = name(~strncmp(name, '.', 1)) % No files starting with '.'
  댓글 수: 2
faran
faran 2016년 12월 6일
Thanks, it worked.
Alikouider
Alikouider 2022년 1월 28일
We have the whole extension...
How can I get only the simulink file please?
'.slx ' files? from the folder
thanks in advance

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Adam
Adam 2016년 12월 6일
편집: Adam 2016년 12월 6일
If you just mean you want to strip out hidden files then there are probably numerous ways to do it, e.g.
import java.io.*;
f = File( filename );
hidden = get( f, 'Hidden' );
That works for a single file. You can easily apply it to a group of files. There is probably a similar java.io package/class that simply allows you to filter them straight out of a directory listing too, but it is ages since I used java.io.File in my work so I can't remember much about it.
f = File( myDirectory );
files = f.listFiles( );
will give you an array of java file objects to loop through too.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by