小記——linux複製檔案與重新命名
阿新 • • 發佈:2019-01-04
1. 重新命名
#include <stdio.h>
int rename (const char *oldpath, const char *newpath);
兩個檔案必在同一檔案系統中,目錄是不能複製的。
2. 複製
linux系統中並沒有提供檔案複製的系統呼叫或C語言函式,這個功能要自己實現,一般步驟為:
In copying a file src to a file named dst, the steps are as follows:
1. Open src.
2. Open dst, creating it if it does not exist, and truncating it to zero length if it does exist.
3. Read a chunk of src into memory.
4. Write the chunk to dst.
5. Continue until all of src has been read and written to dst.
6. Close dst.
7. Close src.
If copying a directory, the individual directory and any subdirectories are created via mkdir(); each file therein is then copied individually.