Problem with "ls" command

24 次查看(过去 30 天)
Ali Razavi
Ali Razavi 2022-11-13
编辑: Marcel 2022-11-17
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.

回答(3 个)

Image Analyst
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.

Marcel
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
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
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
Ali Razavi 2022-11-16
编辑:Ali Razavi 2022-11-16
Hello,
Thanks for input.
The strange issue disappeared on its own.
For a while, for some unkown reason "ls" would list all files in directory correct if the "directory" was its argument. However, it would not see "some" of those file when "ls" was applied to "individual" files in that directory. Oddly, the files shared same name length and naming convention (their difference was in enumeration, e.g., 231, 273, ...). Attempting to read those files in MATLAB was impossible, while outside MATLAB they were accessible & readable. For some reason, MATLAB could not see certain files.
As strange as it started, it disappeared. Maybe after disconnecting/reconnecting external hard drive and re-starting MATLAB and PC? Not sure. But for now things are good.
Thanks for your attention and all the help.
Have a great day.
  3 个评论
Image Analyst
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.
Marcel
Marcel 2022-11-17
编辑:Marcel 2022-11-17
Well yes of course same as with the windows explorer.
It seems like he wanted to see whats inside a file so i made a "simplified" answer to that, and so far my statement isnt wrong as well as yours :P (meaning yours is correct too)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by