Listing C: folder contents
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
dpb
2021-6-15
"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 个评论
dpb
2021-6-15
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!