getFileAttributes method of FileIdBothDirectoryInformation results value as 48 for directory.
kvaishnavi97 opened this issue · 3 comments
Hello,
I am using SMBJ 0.11.5 version. I have implemented a file browser using this api.
With the help of list method of diskshare, I am listing out files/folders from a specific path as below.
for (FileIdBothDirectoryInformation f : diskShare.list(pathname)) { SMBFile SMBFile=new SMBFile(String.format(format_pattern, normalizedPathName, file.getFileName()), FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() == file.getFileAttributes()); }
Here, I am determining FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() == file.getFileAttributes()
whether returned object is a file or folder.
By default, folder/directory FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue()
value is 16. This works fine with some folders.
But getFileAttributes method returning value for below folders as 48 which is wrong (Attached screenshot).
Thanks.`
Here, MODAL,VIBRATION, MECHANICAL are folders but they do not come as directories because the getFileAttribute method does not give a value 16.
getFileAttributes()
delivers a long value which you should bitwise AND, instead of checking equality.
So this would be the right check FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() & file.getFileAttributes() > 0
Or you could use the EnumWithValue.EnumUtils.isSet(file.getAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY)
helper method.
getFileAttributes()
delivers a long value which you should bitwise AND, instead of checking equality.So this would be the right check
FileAttributes.FILE_ATTRIBUTE_DIRECTORY.getValue() & file.getFileAttributes() > 0
Or you could use the
EnumWithValue.EnumUtils.isSet(file.getAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY)
helper method.
Yeah, I got it that later. Anyway, thank you for quick reply.