Possible error in the "fileattrib" function in Matlab. Workaround?

I found strange behavior in the matlab fileattrib function on Windows. For certain file names, it incorrectly identifies the file as a hidden system folder.

To test it, download this file (the file is empty, this is important only for the file name):

https://docs.google.com/file/d/0B9BeckFuQk1bNHY3T0NKaFpxbUU/edit?usp=sharing

Put the file in an empty folder (I use "c: \ temp") and try the following:

 fileattrib('c:\temp\*') 

If your Matlab is like mine, it will give you this wrong result:

 ans = Name: 'c:\temp\?aaa.txt' archive: 1 system: 1 hidden: 1 directory: 1 [...] 

Now rename the file name by deleting the first character and try again. He will say correctly

 ans = Name: 'c:\temp\aaa.txt' archive: 1 system: 0 hidden: 0 directory: 0 [...] 

I saw this behavior in Matlab R2010b and R2007a, in Windows Vista and 7.

The problem is clearly related to some โ€œoffensiveโ€ characters (or character sets / encodings?), But I have no idea. Can anyone understand why this is happening? And how to get around this?

EDIT

This seems to be fixed in R2015a (maybe earlier): it returns correctly

  Name: 'C:\Users\Luis\Desktop\tmp\ aaa.txt' archive: 1 system: 0 hidden: 0 directory: 0 [...] 
+4
source share
1 answer

One way to handle this is to not depend (solely) on the fileattrib .

To determine if something is a file or a directory, you can check how it is registered using the dir command in the containing folder.

This is a bit of a hassle, but when using dir called in a folder (will not work when called directly in a file), you seem to get the correct output.


A quick and dirty alternative, of course, would be to have all your processing built in a try / catch construct, and if you can't just try another.

+1
source

Source: https://habr.com/ru/post/1500829/


All Articles