开发者

How do I rename a file?

How can I renam开发者_如何学Pythone a file on unix platform programatically without using the standard rename function?


The historical way to rename a file is to use link(2) to create a new hardlink to the same file, then to use unlink(2) to remove the old name.


The following is a somewhat ironic solution, that does not use the standard rename(2) system call by itself:

#include <stdlib.h>

if (system("mv file1 file2") != 0)
    perror("system");

It's an indirect usage of rename(2), this syscall is invoked by mv(1).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜