名前の変更()、link()が機能しない
ありがとう!
標準の古いC関数を使用してみましたか?
`fopen` the source on one partition
`fopen` the destination on the other partition
LOOP while `fread` > 0
`fread` from the source to a buff
`fwrite` to the dest from a buff
次に、ファイルを閉じます(つまりfclose
)。
これもよりポータブルです。
編集:本当に基本的なものにしたい場合は、スクリプト言語(python / bash)を使用して、数行で実行してみませんか。
これが私がやる方法です。それは非常に単純で、実際のコピーのトリッキーな部分をcp
ツールに残します。これは、このタスクを数年間成功させてきました。
#include <assert.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
int
runvp(int *ret_status, const char *command, const char * const *argv)
{
pid_t pid;
int status;
char * const *execv_argv;
pid = fork();
if (pid == (pid_t) -1)
return -1;
if (pid == 0) {
/*
* Circumvent the C type conversion rules;
* see ISO C99: 6.5.16.1#6 for details.
*/
assert(sizeof(execv_argv) == sizeof(argv));
memcpy(&execv_argv, &argv, sizeof(execv_argv));
(void) execvp(command, execv_argv);
return -1;
}
if (waitpid(pid, &status, 0) == -1)
return -1;
*ret_status = status;
return 0;
}
これはラッパーでfork
ありexecvp
、私が数年前に書いたものです。次のように使用できます。
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int exitcode;
const char *cmdline[] = {
"cp",
"--",
argv[1],
argv[2],
NULL
};
if (runvp(&exitcode, cmdline[0], cmdline) == -1) {
perror("runvp");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
rename()が機能するはずです。返されるエラーを確認しましたか?ドキュメントに従って成功した場合、rename()は0を返します。
http://www.cplusplus.com/reference/clibrary/cstdio/rename/
perror()を使用して、エラー文字列を標準エラー(stderr、通常は画面)に出力できます。