Linux C 檔案複製的實現

2021-06-20 09:11:01 字數 864 閱讀 8862

參考網上的**,整理的比較完整的,關於使用read()和write()函式,實現檔案拷貝的**。

執行結果:

/* 開啟原始檔 */

if ((from_fd = open (argv[1], o_rdonly)) == -1)

/* 建立目標檔案 */

if ((to_fd = open (argv[2], o_wronly | o_creat, s_irusr | s_iwusr)) == -1)

/* 迴圈獲得原始檔內容,並寫進目標檔案 */

while (bytes_read = read (from_fd, buffer, buffer_size))

else if (bytes_read > 0)

/* 寫完了所有讀的位元組 */

else if (bytes_write == bytes_read)

/* 只寫了一部分,繼續寫 */

else if (bytes_write > 0)

}/* 寫的時候發生的致命錯誤 */

if (bytes_write == -1)}}

close (from_fd);

close (to_fd);

exit (0);

}

linux c複製檔案方法

這裡主要 用到的函式是 open,read,write include include include include include include include char buff 1024 int len int main int argc,char const argv return 0 ...

Linux C 實現檔案複製 檔案及資料夾刪除功能

linux下的檔案操作其實是個很普通的小功能,linux c提供了一些系統函式可以呼叫,我們使用的時候只需按照自己的需要封裝一下即可。實現檔案從乙個目錄複製到另外乙個目錄,以下是最簡單的操作,正式的工程中為了嚴謹起見,盡量加上錯誤檢查。include include include include ...

Linux C實現更改檔案時間

主要是通過utime 這個函式實現的 標頭檔案 include include 函式定義 int utime const char filename,struct utimbuf buf 函式說明 utime 用來修改引數filename 檔案所屬的inode 訪問時間。結構utimbuf 定義如下...