why I cannot list specify files with function dir
3 views (last 30 days)
Show older comments
I want to list all special files with specified extensions, such as all *.jpg files. I cd the matlab to the current folder, and call the dir function as following:
dir *.jpg
it does not return all file names but a struct with name attribute and other fields, like the following picture showing
If I call dir function as following:
dir
it will return all files
I just want to list all jpg files, but not including the root directory, how to use dir function, please?
9 Comments
Guillaume
on 9 May 2018
I wanted to see the end of the list of files. From the screenshot you show in KSSV answer, it looks like somehow you have a file actually called '*.jpg' in that directory. Something I didn't think was possible on Windows.
What is the output of
s = dir('*.jpg');
double(s.name)
Accepted Answer
Jan
on 9 May 2018
Edited: Jan
on 9 May 2018
Guillaume is right: You have created a file called '*.jpg'. This is not possible under Windows with standard tools, but you can do this under Linux or with using evil tricks. I suggest to start your machine from a Linux live CD or USB stick and delete the file '*.jpg'.
You can install the Linux subsystem: https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2008-R2-and-2008/cc771470(v=ws.11) (here for Windows 7) and delete the file from there.
This works for a trailing dot in the file name, which is illegal also:
system('del \\?\D:\Temp\asd.')
I cannot test this with a * in the name, because I'm not able to create such a file...
A chkdsk might fix the file name also.
2 Comments
Guillaume
on 9 May 2018
This is why I wanted a screenshot of the end of the file listing. Everything points to a file called *.jpg in the current directory.
How you would create such a file in Windows is a mystery. The WIN32 API won't let you. I suggest copying all the valid files into a new directory then deleting the current directory with the invalid *.jpg file (if the OS actually lets you).
More Answers (1)
See Also
Categories
Find more on File Operations in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!