1.c 语言获取当前时间以及时间的格式化
//get current time
char *gettime(){
time_t timep;
time(&timep);
char tmp[64];
strftime(tmp, sizeof(tmp), "%Y%m%d%H%M%S", localtime(&timep));
return tmp;
}
2.c语言创建文件夹
char *file_path="path";
_mkdir(file_path);
3.C语言删除文件夹(文件夹中包含文件)
void show_classify::delete_directory(std::string dirPath)
{
struct _finddata_t fb; //查找相同属性文件的存储结构体
char path[250];
//should notice here,the type of handle is long long.
long long handle;
int resultone;
int noFile; //对系统隐藏文件的处理标记
noFile = 0;
handle = 0;
//制作路径
strcpy(path, dirPath.c_str());
strcat(path, "/*");
handle = _findfirst(path, &fb);
//找到第一个匹配的文件
if (handle != 0)
{
//当可以继续找到匹配的文件,继续执行
while (0 == _findnext(handle, &fb))
{
//windows下,常有个系统文件,名为“..”,对它不做处理
noFile = strcmp(fb.name, "..");
if (0 != noFile)
{
//制作完整路径
memset(path, 0, sizeof(path));
strcpy(path, dirPath.c_str());
strcat(path, "/");
strcat(path, fb.name);
//属性值为16,则说明是文件夹,迭代
/*if (fb.attrib == 16)
{
delete_directory(path);
}*/
//非文件夹的文件,直接删除。对文件属性值的情况没做详细调查,可能还有其他情况。
/*else
{*/
remove(path);
/*}*/
}
}
//关闭文件夹,只有关闭了才能删除。找这个函数找了很久,标准c中用的是closedir
//经验介绍:一般产生Handle的函数执行后,都要进行关闭的动作。
_findclose(handle);
}
//移除文件夹
resultone = rmdir(dirPath.c_str());
}