rename linux 函數

C標準函數,似乎不應該有平臺問題:

我們看一下這個程序:

#include
#include
int main()
{
    rename(”/tmp/abc”,”/tmp/bcd”);
    perror(”why:”);
}

此程序運行一切正常。

自己將路徑修改爲不同的分區之間移動,或者將同一分區掛載到不同的mount點進行rename。
看看結果會怎麼樣。

man 2 rename
oldpath and newpath are not on the same mounted filesystem.  (Linux permits  a  filesystem  to  be
              mounted at multiple points, but rename(2) does not work across different mount points, even if the
              same filesystem is mounted on both.)

在Windows上嘗試:
rename(”C://a.txt”,”D://b.txt”);

works!!

 

fangjtan:

當rename(oldpath,“1”);則將oldpath的文件移動當前目錄,且文件名更名爲1;

來自:http://www.linux-ren.org/modules/everestblog/?p=141
發佈了37 篇原創文章 · 獲贊 4 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章