get_contents

Get the contents of a specified directory
다운로드 수: 589
업데이트 날짜: 2018/5/5

NOTE: this function is now available from the IoSR Matlab Toolbox as iosr.general.getContents.
-------------------------
cont = get_contents(directory)
cont = get_contents(directory,options)
[cont,dirflag] = get_contents(...)

This function returns the contents of a specified directory.

cont = get_contents(directory) returns the files and folders in directory and returns them to the cell array cont. It ignores hidden files and folders (those starting '.'). Directory must be a character array (string).

cont = get_contents(directory,options) allow search options to be specified. The options are specified in parameter/value pairs, and include:
'rec' {false} | true
Search recursively within the subfolders of the specified directory.
'path' {'relative'} | 'full'
Specifies whether returned paths are full or relative to the specified directory.
'sort' {false} | true
Specify whether the output is sorted alphabetically.
'filter' {'all'} | 'files' | 'folders' | '*.ext' | str
This option allows a filter to be specified. 'files' returns names of all files in the directory. 'folders' returns names of all folders in the directory. '*.ext', where 'ext' is a user-specified file extension, returns all files with the extension '.ext'. str may be any string; only elements that contain str will be returned (files or folders). str is case-sensitive.

[cont,dirflag] = get_contents(...) returns a logical array dirflag, the same size as cont, indicating whether each element is a directory.

Examples

Ex. 1

% Return all m-files in the current directory

cont = get_contents(cd,'filter','*.m')

Ex. 2

% Return all files in the current directory and its
% sub-directories

cont = get_contents(cd,'rec',true)

Ex. 3

% Return all files in current directory with names
% containing 'foo'

% may return files and folders:
[cont,dirflag] = get_contents(cd,'filter','foo')

% use dirflag to limit:
cont = cont(~dirflag);

인용 양식

Christopher Hummersone (2024). get_contents (https://github.com/IoSR-Surrey/MatlabToolbox), GitHub. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2010b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Search Path에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

GitHub 디폴트 브랜치를 사용하는 버전은 다운로드할 수 없음

버전 게시됨 릴리스 정보
1.8.0.0

Minor update to file help text and description.
Migrated to GitHub.

1.7.0.0

Minor update to help text and description.

1.6.0.0

Simplified interface such that str is not required (now varargin option). Also made sort and rec flags logical rather than strings.

1.4.0.0

Some bug fixes and additional inputs options permitted, including a recursive option. Input now in parameter/value pairs.

1.3.0.0

Some bug fixes. Additionally outputs a directory flag.

1.2.0.0

Added a keyword, allowing specific file extensions to be returned

1.1.0.0

Updated help

1.0.0.0

이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.
이 GitHub 애드온의 문제를 보거나 보고하려면 GitHub 리포지토리로 가십시오.