如何打印由c中的符号链接指向的文件的路径,例如树或ls -l di

发布于 2025-01-27 12:49:18 字数 363 浏览 2 评论 0原文

这是我的问题: 我用C语言写一个简化的树命令。 当我找到一个符号链接的文件时,我会打印类似的内容:

smybolicfile-> ../../.././ something ..

所以我尝试使用readlink()函数来执行此操作,但是它并未像LS -L或TROED命令一样打印指向符号链接的文件。

例如: 如果我的符号链接文件有0/1/2/3/符号,并且指向的文件在0/1/a/b/filepointed中。

我的程序打印:符号 - > 0/1/a/b/filepoint 但是我想要这个:象征性 - > ../../../../././a/b/filepointed(如ls -l或树所做的)。

那么,这是什么方法呢?

here's my problem:
Im writing a simplified tree command with C language.
When I find a file that's a symbolic link i would print something like:

SymbolicFile -> ../.././something..

So i've tried to do that using readlink() function, but it does not print the file pointed to the symbolic link as the ls -l or tree command does.

for example:
if my symbolic link file is there 0/1/2/3/symbolic and the file pointed is in 0/1/a/b/filepointed.

My program prints: symbolic -> 0/1/a/b/filepointed
But i want this: symbolic -> ../../.././a/b/filepointed (as ls -l or tree does).

So what would be a way to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文