LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I programmatically hide a folder (not a file) in windows using CVI?

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

0 Kudos
Message 1 of 7
(2,849 Views)

Hi,

Can you use the window function:

SetFileAttributes(szDirName, FILE_ATTRIBUTE_HIDDEN);

 

0 Kudos
Message 2 of 7
(2,826 Views)

I have tried it. This only hides a file not a folder.

0 Kudos
Message 3 of 7
(2,799 Views)

Hi,

It works on my machine:

Capture.PNG

You should see a file attribute named H.

Also select hidden files and folders in folder option setup.

Capture.PNG

0 Kudos
Message 4 of 7
(2,791 Views)

That works, but how do I programmatically do that in CVI?

Thanks for your response.

 

Bob

0 Kudos
Message 5 of 7
(2,770 Views)

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? 

Claire M.
Technical Support
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 6 of 7
(2,734 Views)

@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.

Rolf Kalbermatter
My Blog
Message 7 of 7
(2,730 Views)