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!