Problem with "ls" command
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (3)
Image Analyst
el 13 de Nov. de 2022
Movida: Image Analyst
el 15 de Nov. de 2022
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 comentarios
Marcel
el 15 de Nov. de 2022
Editada: Marcel
el 16 de Nov. de 2022
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 comentarios
Image Analyst
el 15 de Nov. de 2022
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
el 16 de Nov. de 2022
Editada: Marcel
el 16 de Nov. de 2022
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
el 16 de Nov. de 2022
Editada: Ali Razavi
el 16 de Nov. de 2022
3 comentarios
Image Analyst
el 16 de Nov. de 2022
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.
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!