フィルターのクリア

Redirection using Unix 'ls' list command

4 ビュー (過去 30 日間)
Eric Hong
Eric Hong 2011 年 2 月 8 日
Hi,
I quite often use the following command in PC Matlab (as opposed to running Matlab in Unix environment):
!ls *mat > temp.txt;
or
system('ls *mat > temp.txt');
which lists all .mat files, creates a text file, and saves the data file names, one on each line, into the text file. This is very nice.
The thing is that the above command only works on my machine for some reason. I recently found out that none of my coworkers can execute the command although they have exact OS, Matlab version, etc.
I had to modify my scripts using 'dir' or 'diary' instead of 'ls >' for them.
Does anybody have any idea?
Thanks in advance,
Eric
  1 件のコメント
Andrew Newell
Andrew Newell 2011 年 2 月 8 日
It works for me on a Mac with OS 10.6 (Snow Leopard). What goes wrong when you do it?

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

採用された回答

Walter Roberson
Walter Roberson 2011 年 2 月 8 日
You probably have something like the unix tools installed, or mingw .
! sends the following command to the system shell for the system to process. The command is not processed by Matlab at all. The same with system(). The Matlab version does not matter for this question.
Using command/function duality, you could write a Matlab function named "ls" that did this kind of listing and even looked for the '>' to know where to write the output.
ls *.mat > file.txt
is valid Matlab syntax, meaning
ls('*.mat', '>', 'file.txt')

その他の回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2011 年 2 月 8 日
The bang(!) operator and system command essentially redirect the command to the system shell - is it likely that you have a Windows utility installed that defines 'ls'? You can test this by typing 'ls' at your Windows command prompt.

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by