Linux下如何找到C文件路径下子文件夹的权限?
我试图查找文件路径中具有“其他执行”权限的所有子文件夹。
我尝试使用 strtok(path_str,"/")
来破坏路径字符串,但是当使用 stat()
作为根目录的子目录时我运行的过程中,收到“不是文件或文件夹”错误。
关于如何克服这个错误有什么建议吗?
I'm trying to find all subfolders in a file's path that have 'others exec' permission.
I've tried to use strtok(path_str,"/")
to break the path string, but when using stat()
for the sub-directories of the root of the process I run, I get the "not a file or folder" error.
Any suggestions on how I can overcome this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果路径是
"long/path/to/the/file.txt"
,那么您需要对"long"
调用stat()
代码>,<代码>“长/路径”,<代码>“长/路径/到”和<代码>“长/路径/到/该”。如果您不关心检查这些内容的顺序,最简单的方法可能是重复使用strrchr()
:(特殊情况适用于以
/
开头的路径,检查根目录本身)。If the path is
"long/path/to/the/file.txt"
, then you will need to callstat()
on"long"
,"long/path"
,"long/path/to"
and"long/path/to/the"
. If you don't care in what order you check these, the easiest way is probably to repeatedly usestrrchr()
:(The special-casing is for paths beginning with
/
, to check the root directory itself).我已经修复了它,
首先我从路径中删除了第一个“/”(我不完全理解为什么会这样)
比我将代码更改为 do-while 以访问最后的文件。
这是完整的代码:
谢谢咖啡馆和所有人的帮助。
I've fixed it,
First I removed the first '/' from the path (I'm not fully understand why it so)
Than I Changed the code into do-while to access the file at the end.
So here is the entire code:
Thank You caf and all for your assistance.