'cross platform way of hiding directories using C++
I created a new directory .store using C++ <filesystem> library. Although the name of the directory starts with a ., it is visible in File Explorer on Windows.
I learnt that it is possible with Windows API. But this works only for Windows.
Is there a way to create a hidden folder named .store using C++ which will work for all platforms? Or I should determine the platform and implement OS-specific APIs?
Solution 1:[1]
On Windows, a file/folder starting with a . in its name is not treated any different than any other file/folder. The only way to "hide" such a file/folder is to explicitly set the FILE_ATTRIBUTE_HIDDEN attribute on the file/folder, such as with SetFileAttributes() or equivalent. The <filesystem> library will not do this for you, so yes, your code will need to detect the platform and call the appropriate API as needed.
You say that your goal is to hide the folder from File Explorer (known as Windows Explorer prior to Windows 10). Just note that Explorer has a user-configurable option to show hidden files/folders, so you can't truly hide from the user if they don't want you to.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
