Problem with "ls" command
24 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I have encountered a strange issue.
There is a directory that has 29 files, as an example 2 of them are listed here.
However, when I try listing them indivisually only one of them gets listed:
>> T=ls('D:\2022_11_08_001_FWHM\20221011_FB0031471-BCC_PSQ007_8\AF_CALIBRATION\2022-10-11-12-58-56-876\L02\S02\T054\')
T =
'seq_Z_-00231.tiff '
'seq_Z_-00273.tiff '
>> ls('D:\2022_11_08_001_FWHM\20221011_FB0031471-BCC_PSQ007_8\AF_CALIBRATION\2022-10-11-12-58-56-876\L02\S02\T054\seq_Z_-00273.tiff')
seq_Z_-00273.tiff
>> ls('D:\2022_11_08_001_FWHM\20221011_FB0031471-BCC_PSQ007_8\AF_CALIBRATION\2022-10-11-12-58-56-876\L02\S02\T054\seq_Z_-00231.tiff')
'D:\2022_11_08_001_FWHM\20221011_FB0031471-BCC_PSQ007_8\AF_CALIBRATION\2022-10-11-12-58-56-876\L02\S02\T054\seq_Z_-00231.tiff' not found.
0 件のコメント
回答 (3 件)
Image Analyst
2022 年 11 月 13 日
移動済み: Image Analyst
2022 年 11 月 15 日
It seems ls() thinks there is a space or two after the extension. You are not adding that space when you call ls() for individual files.
0 件のコメント
Marcel
2022 年 11 月 15 日
編集済み: Marcel
2022 年 11 月 16 日
I think there is a small error. This works fine because the file path is a directory.
>> T=ls('D:\2022_11_08_001_FWHM\20221011_FB0031471-BCC_PSQ007_8\AF_CALIBRATION\2022-10-11-12-58-56-876\L02\S02\T054\')
T =
'seq_Z_-00231.tiff '
'seq_Z_-00273.tiff '
Tho on this one in your second example, you included a filename. I guess the problem is that you try to list a file that you've already specified in the path in your ls command.
>> ls('D:\2022_11_08_001_FWHM\20221011_FB0031471-BCC_PSQ007_8\AF_CALIBRATION\2022-10-11-12-58-56-876\L02\S02\T054\seq_Z_-00273.tiff')
seq_Z_-00273.tiff
If seq_Z[...].tiff is a directory, then this is a strange issue.
4 件のコメント
Image Analyst
2022 年 11 月 15 日
Well when you said the reason why it said "file not found" when he gave LS the name of a particular file was "the problem is that you try to list a file that you've already specified." I assumed you meant that the file was already found/listed when he first used ls to get a list of all files in the folder. What did you mean when you said it was "already specified"? And why would specifying arguments to ls twice make it not work the second time?
Marcel
2022 年 11 月 16 日
編集済み: Marcel
2022 年 11 月 16 日
Oh no sorry.
I meant like if you call ls("path\to\smth\file.txt") then you would've already specified the filein the ls command, so it would only return that filename of course. earlier he made a ls call like ls("path\to\smth\") without a filename, so the command would return all the files in the directory specified.
See this example. When calling dir it shows me all the files etc in that directory, but if i use dir with the filename it only returns that same filename
Ali Razavi
2022 年 11 月 16 日
編集済み: Ali Razavi
2022 年 11 月 16 日
3 件のコメント
Image Analyst
2022 年 11 月 16 日
ls can also list one or more filenames if you give a file pattern. It does not just work on directories alone. For example these both list the same files:
dir('test.*')
ls('test.*') % File name pattern, not a folder.
@Ali Razavi didn't say what he was going to do with the files once he got their name(s) but if he wants to open them or something, then he can change the inside of the loops in the code snippets in the FAQ:
to do whatever he wants to do with the file.
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!