开发者

C Stat() failing on files in hidden folder

开发者 https://www.devze.com 2023-02-18 15:06 出处:网络
This is a piece of my code. It works fine if I use opendir on just \".\", but when I try and open /.hidden, the stat fails. Does stat not work on files in a hidden folder, or am I doing something wron

This is a piece of my code. It works fine if I use opendir on just ".", but when I try and open /.hidden, the stat fails. Does stat not work on files in a hidden folder, or am I doing something wrong?

direc = opendir("./.hidden");

if(direc ==NULL)
{
    perror("opendir failed");

}

while((curr_file=readdir(direc)))
{
    if(( strcmp(curr_file->d_name,".")!=0 && strcmp(curr_file->d_name,"..")!=0))
    {
        strcpy(file_name,".");
        strcat(file_name,"/");
        strcat(file_name,curr_file->d_name);
        if(stat(file_name,&st开发者_开发百科atp))
        {
            perror("stat failed");
        }


You neglected to update the code that builds the file name, so it's trying to stat("./filename") instead of stat("./.hidden/filename").

0

精彩评论

暂无评论...
验证码 换一张
取 消