Listing C: folder contents

9 visualizaciones (últimos 30 días)
David Young
David Young el 15 de Jun. de 2021
Comentada: David Young el 15 de Jun. de 2021
Does anyone know why, in Windows 10 with R2021a, the command
dir("C:")
returns a listing of files in the current folder? I can't see this behaviour mentioned in the documentation.
I realise that
dir("C:\")
does what I'd expect, so I can solve the problem in my own code, but I'm wondering whether to report this as a bug, or whether I've missed something.
When I have another drive attached,
dir("D:")
and
dir("D:\")
behave identically to each other (listing the top-level folder contents for the drive), and I'd expect the results to be consistent across drives.
The dir command in the Windows command shell behaves in this way, but that's no reason for the MATLAB command to do the same thing, unless it's stated in the MATLAB documentation.

Respuestas (1)

dpb
dpb el 15 de Jun. de 2021
"The dir command in the Windows command shell behaves in this way, but that's no reason for the MATLAB command to do the same thing,..."
I think it's a very good reason for MATLAB to do so; it's consistent with the OS (and more than likely all dir() is doing is passing the input string to the OS command and returning its output in the consistent struct, anyway).
It's nothing new nor different, earlier releases and versions of Windows also behave the same way.
The documentation is mum on the precise subject -- it doesn't make any claims one way or t'other for the particular case.
  3 comentarios
dpb
dpb el 15 de Jun. de 2021
Well, the last point first is that changing behavior may break previous code so changing behavior isn't free--it may not be an issue for the new user, but those (like me also) who've used it for a long time could be bit.
As for the first, I would argue if one is using the product on the OS, consistency with the OS is to be desired; I often will pass the command to the OS in order to get back what can sometimes be done there that can't in the neutered MATLAB version -- other switches or wildcard patterns, etc., etc., ... if they returned different results, that's also a pain to handle.
Now, whether Bill and company did right by implementing it the way they did is a whole different story; I wouldn't argue there that alternate choices could have been made.
I just wouldn't expect either to change at this late date, though...although I could see there being some additional caveats in the ML documentation, maybe.
David Young
David Young el 15 de Jun. de 2021
Sure - I do agree the behaviour shouldn't change now - I guess I'm mainly thinking the documentation could have been more helpful. I'll send in feedback by the official mechanism.

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by