dir command help!

25 ビュー (過去 30 日間)
Leonardo Wayne
Leonardo Wayne 2016 年 3 月 17 日
編集済み: Anand Swaroop 2021 年 12 月 7 日
I am trying to understand the dir command. I am looking section that List the contents of a folder. the syntax is dir my_folder , is my folder in the current directory or it must be a string like'C:\......my 'folder Reference: http://uk.mathworks.com/help/matlab/ref/dir.html?searchHighlight=dir#inputarg_name

回答 (1 件)

Anand Swaroop
Anand Swaroop 2021 年 12 月 7 日
編集済み: Anand Swaroop 2021 年 12 月 7 日
Dir function lists the files and folders in current directory.
The argument ‘my_folder you mentioned should be a directory path, either absolute or relative.
For example, if you are in the path
C:/demo/my_dir.
then following both are valid usages
dir('.')
dir('C:/demo/my_dir')
If you try it from parent directory i.e. C:/demo, you can pass relative path also
dir('my_dir')
You can also pass a variable which contains the valid path
dirpath='my_dir'
dir(dirpath)
Hope this will be helpful to you
Best Regards
Anand Swaroop
  3 件のコメント
Jan
Jan 2021 年 12 月 7 日
dir(.) is no valid Matlab syntax. Better: dir('.').
Avoid using "path" as name of a variable. This is not an error at runtime, but during debugging shadowing the important function path() might have very strange side effects.
Anand Swaroop
Anand Swaroop 2021 年 12 月 7 日
@Jan correction done. thanks for pointing out.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by