About: Master Student in CS, Open source developer, working on Web Desktop Environment and 3D Modeling Tools
Location:
Hong Kong
Joined:
Oct 18, 2020
Hide a file / folder using Golang
Publish Date: Sep 11 '21
3 5
Recently, one of my clients is requesting me to develop a web system that runs on Windows (instead of Linux). What they thought is that they don't need to hire an IT guy to do the daily maintenance and they can fix / update the system even without much technical knowledge in the field.
As I am a "nice" developer, I say "sure", but the next things I am thinking is: How do I hide all the files that should not be touched securely? After some Googling, I decided to hide all the system generated files using Windows API. I also want to keep the Linux compatibility of the system (just in case they hire an actual IT guy later and decided to migrate to Linux), so I made this simple Go Module to get the job done.
Go module to set a hidden folder and check if a folder is hidden
goHidden
A Go module to set a folder hidden and check if a folder is hidden
Support Windows and Linux, should also work on MacOS
Usage
//Hide a folder
err := hidden.HideFile("./test")
if err != nil {
panic(err)
}
//Check if a folder is hidden
isHidden, err := hidden.IsHidden("./test", false)
if err != nil {
panic(err)
}
You can enable parent directories checking on IsHidden by passing "true" as the last parameter for IsHidden. This will allowIsHidden to check all the upstream folders to see if the file is located inside a hidden folder. Set this to false for checking only the targeted file / folder.
hidden.HideFile("./test")
isHidden, _ := hidden.IsHidden("./test/myfile.txt", true)
//isHidden is true
This does not hide the file but just add the
.
in the prefix.