Search code examples
clinuxfopen

fopen hidden files in c language


I am using ubuntu linux and i am just a beginner is c language i have created a program that creates a lock file when started inside a folder but both the file and folder are with [DOT] like .folder and .file and linux hides such files and folders and i have another program that checks if the file exists or not if it exists then the program is running and if it doesn't then its not simple here is my code

FILE* lockfile = fopen("/.folder/.lock", "r");
if (!lockfile) {
    printf("Cannot find lock file");
} else {
    printf("lock file found");
}

the folder is in the root directory and i just wanna read the file so i gave "r" as the access i made a lot of search but only found answers to windows based programs can anyone point out where am i wrong or any solution for it? how can i read hidden files and folders in linux through c?

EDIT: added images to make things a bit more clear

folder

The .folder directory it has all the permission for the current user

file The .lock file also has the read permission for the current user so i don't think there is a problem with the permission or i am still wrong?


Solution

  • There is no such thing as a "hidden" file in *nix. The leading dot is a convention followed by tools to inhibit their display, but there is no difference between them and any other filesystem object of the same type in the system.