Friday, July 31, 2009

dir

Display directory listing

Syntax

  • dir
    dir name
    files = dir('name')

Description

dir lists the files in the current working directory.

dir name lists the specified files. The name argument can be a pathname, filename, or can include both. You can use absolute and relative pathnames and wildcards (*).

files = dir('directory') returns the list of files in the specified directory (or the current directory, if dirname is not specified) to an m-by-1 structure with the fields


name
Filename
date
Modification date
bytes
Number of bytes allocated to the file
isdir
1 if name is a directory; 0 if not

Examples

List Directory Contents

To view the contents of the matlab/audio directory, type

  • dir $matlabroot/toolbox/matlab/audio

Using Wildcard and File Extension

To view the MAT files in your current working directory that include the term java, type

  • dir *java*.mat

MATLAB returns

  • java_array.mat  javafrmobj.mat  testjava.mat

Using Relative Pathname

To view the M-files in the MATLAB audio directory, type

  • dir(fullfile(matlabroot,'toolbox/matlab/audio/*.m'))

MATLAB returns

  • Contents.m          auread.m            soundsc.m
    audiodevinfo.m auwrite.m wavplay.m
    audioplayer.m lin2mu.m wavread.m
    audioplayerreg.m mu2lin.m wavrecord.m
    audiorecorder.m prefspanel.m wavwrite.m
    audiouniquename.m sound.m

Returning File List to Structure

To return the list of files to the variable audio_files, type

  • audio_files=dir(fullfile(matlabroot,'toolbox/matlab/audio/*.m')
    )

MATLAB returns the information in a structure array.

  • audio_files =
    19x1 struct array with fields:
    name
    date
    bytes
    isdir

Index into the structure to access a particular item. For example,

  • audio_files(3).name
    ans =
    audioplayer.m

No comments:

Post a Comment