读书人

在C语言中有没有删除文件夹的函数啊知

发布时间: 2012-03-03 15:33:03 作者: rapoo

在C语言中有没有删除文件夹的函数啊??知道的请告诉我下谢谢~ 谢谢~~~~~
在C语言中有没有删除非空文件夹的函数啊??
我用
int status;
status=rmdirrmdir(c5[3]);
(!status)?(printf( "Directory deleted %s ",c5[3])):(printf( "Unable to delete directory %s ",c5[3]));

为什么不能删除非空文件夹??
高手解决下 谢谢谢谢

[解决办法]
没有 要调用系统API的
如果是WINDOWS:
删除目录RemoveDirectory
函数原型:
BOOL RemoveDirectory)
LPCTSTR lpPathName //point to directory to remove
);
DeleteFile删除文件
函数原型
BOOL DeleteFile(
LPCTSTR lpFileName // pointer to name of file to delete
);
例如:
。。。。。。。。。。。。。
DeleteFile( "C:\\Windows\\Desktop\\Example.TXT ");
。。。。。。。。。。。。。


[解决办法]
只有删除空目录的rmdir函数,没有直接删除非空目录的函数,这个功能需要自己来实现,先删除目录下的所有文件再用rmdir删除目录。
[解决办法]
我看了一下手册,好象没有

不过你可以

假如文件名是个常量
用system( "del filename ");

假如文件名是个变量
char target[32]= "\0 ";
strcat(target, "del ");
strcat(target, filename);
system(target);
[解决办法]
#include <stdio.h>
#include <conio.h>

int main()
{
int Flag;
system( "cls ");
Flag = mkdir( "abcdefg ");
(!Flag)?(printf( "Directory created! ")):(printf( "Unable to create directory! "));
getch();
system( "dir ");
getch();
Flag = rmdir( "abcdefg ");
(!Flag)?(printf( "Directory deleted ")):(perror( "Unable to delete directory "));
getch();
system( "dir ");
system( "PAUSE ");
return 0;
}

读书人网 >C语言

热点推荐