Listing C: folder contents
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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.
0 commentaires
Réponses (1)
dpb
le 15 Juin 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 commentaires
dpb
le 15 Juin 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.
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!