创建文件&复制文件&删除文件
2017-06-21 22:49
330 查看
#include
#include
#include
#include
#include
#include
char buf[60];
int count;
void main(int argc, char *argv[])
{
int a = argc;
int fd, fd1, fd2;
int flag;
char ch;
printf("%s\n",
argv[1]);
if(strcmp(argv[1],
"myvim") == 0)
{
fd = open(argv[2],
O_RDWR|O_CREAT|O_APPEND, S_IRWXU);
close(fd);
}
if(strcmp(argv[1],
"mycp") == 0)
{
count = 0;
fd1 = open(argv[2],
O_RDWR|O_APPEND, S_IRWXU);
if(fd1 < 0)
{
printf("there is no that file!\n");
return;
}
fd2 = open(argv[3],
O_RDWR|O_CREAT|O_APPEND, S_IRWXU);
while( (count =
read(fd1, buf, 50)) && (count == 50) )
{
write(fd2, buf, 50);
}
if(count < 50)
{
write(fd2, buf, count);
}
close(fd);
}
if(strcmp(argv[1],
"myrm") == 0)
{
printf("are you sure
want to delete the file?\n");
scanf("%c",
&ch);
if(ch == 'y')
flag =
unlink(argv[2]);
}
}
#include
#include
#include
#include
#include
char buf[60];
int count;
void main(int argc, char *argv[])
{
int a = argc;
int fd, fd1, fd2;
int flag;
char ch;
printf("%s\n",
argv[1]);
if(strcmp(argv[1],
"myvim") == 0)
{
fd = open(argv[2],
O_RDWR|O_CREAT|O_APPEND, S_IRWXU);
close(fd);
}
if(strcmp(argv[1],
"mycp") == 0)
{
count = 0;
fd1 = open(argv[2],
O_RDWR|O_APPEND, S_IRWXU);
if(fd1 < 0)
{
printf("there is no that file!\n");
return;
}
fd2 = open(argv[3],
O_RDWR|O_CREAT|O_APPEND, S_IRWXU);
while( (count =
read(fd1, buf, 50)) && (count == 50) )
{
write(fd2, buf, 50);
}
if(count < 50)
{
write(fd2, buf, count);
}
close(fd);
}
if(strcmp(argv[1],
"myrm") == 0)
{
printf("are you sure
want to delete the file?\n");
scanf("%c",
&ch);
if(ch == 'y')
flag =
unlink(argv[2]);
}
}
相关文章推荐
- JAVA 如何创建/删除/修改/复制目录及文件
- JAVA 如何创建/删除/修改/复制目录及文件
- asp.net文件的,创建,删除,复制,粘贴
- 文件与文件夹的创建、删除、复制
- PHP操作文件类(文件和文件夹创建,复制,移动和删除)
- asp.net中对文件的创建,移动,复制,及删除操作
- JAVA 如何创建/删除/修改/复制目录及文件 (转载)
- C#文件创建、移动、删除、复制
- JAVA 如何创建/删除/修改/复制目录及文件
- 基本的文件 I/O 用法:1.复制目录及其文件 2.文件创建,写入,读取,删除,复制
- JAVA 如何创建\删除\修改\复制目录及文件
- 文件创建、复制、移动、删除
- JAVA操作文件(创建、删除、复制、剪切)
- JAVA 如何创建/删除/修改/复制目录及文件
- JAVA 如何创建/删除/修改/复制目录及文件 3in1
- JAVA 如何创建/删除/修改/复制目录及文件
- 已存在的情况下创建/影像复制该文件"是由什么导致的
- JAVA 如何创建/删除/修改/复制目录及文件 --【转】
- PHP操作文件类的函数代码(文件和文件夹创建,复制,移动和删除)
- C#文件创建、移动、删除、复制