05-22-2018 09:40 PM
In windows, there is CVI code to hide a file. What I want is a code to hide a folder. Is there a function like that in CVI?
Thank you.
Bob
05-23-2018 02:19 AM
Hi,
Can you use the window function:
SetFileAttributes(szDirName, FILE_ATTRIBUTE_HIDDEN);
05-25-2018 11:51 AM
I have tried it. This only hides a file not a folder.
05-28-2018 02:59 AM
Hi,
It works on my machine:
You should see a file attribute named H.
Also select hidden files and folders in folder option setup.
05-30-2018 09:22 AM
That works, but how do I programmatically do that in CVI?
Thanks for your response.
Bob
05-31-2018 04:31 PM
I'm not sure there's a native CVI function that will accomplish this. It looks like most of the directory functions are in utility.h, which is where the function that can hide files lives. There doesn't seem to be a mirrored attribute setting function for directories, though. Have you looked into running a command line argument from CVI and hiding the folder that way?
06-01-2018 02:04 AM - edited 06-01-2018 02:22 AM
@Robert_Mensah wrote:
I have tried it. This only hides a file not a folder.
According to MSDN, SetFileAttribute(dirName, FILE_ATTRIBUTE_HIDDEN); should work for both files and directories.
Obviously you should not change it like this but rather like this:
BOOL success = FALSE; DWORD attr = GetFileAttribute(dirName); if (attr != INVALID_FILE_ATTRIBUTES) { attr |= FILE_ATTRIBUTE_HIDDEN; success = SetFileAttribute(dirName, attr); }
Otherwise the SetFileAttribute() function will fail as you try to delete the FILE_ATTRIBUTE_DIRECTORY flag which this function can explicitly not be used for!!
To change the setting in the control panel how Explorer lists such directories is another story entirely. Generally an application should NOT force changes to a (user configurable) environment setting. If an application does, I consider it hostile and would quite likely deinstall it immediately.