Listing C: folder contents
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
dpb
am 15 Jun. 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 Kommentare
dpb
am 15 Jun. 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.
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!