C++中打开指定目录的函数
2007-09-13 19:07
253 查看
#include <direct.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char tmpbuf[16];//当日目录
void TodayFileName()
{
time_t cur;
struct tm *mt;
cur = time(NULL);
mt = localtime(&cur);
strftime(tmpbuf, 16,"%Y%m%d", mt);
}
bool findfile( char *cFilePath, char *cFileName)
{
//FILE *fp;
char *cMyFilePath = cFilePath;
char *cMyFileName = cFileName;
if( _chdir(cMyFilePath))
{
return 0;
}
else
if((fp == fopen(cMyFileName, "r")) == NULL)
return 0;
else
// else
//system( "dir *.log.1");
}
int main()
{
char cFilePath1[50] = "D://kcxp//log";
char cFileName1[30] = "ERR0001.log.1";
strcat(cFilePath1,"//");
TodayFileName();
strcat(cFilePath1,tmpbuf);
return 0;
}
写好后测试了一下,还行,不过后来又改了,就成现在这样了.
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char tmpbuf[16];//当日目录
void TodayFileName()
{
time_t cur;
struct tm *mt;
cur = time(NULL);
mt = localtime(&cur);
strftime(tmpbuf, 16,"%Y%m%d", mt);
}
bool findfile( char *cFilePath, char *cFileName)
{
//FILE *fp;
char *cMyFilePath = cFilePath;
char *cMyFileName = cFileName;
if( _chdir(cMyFilePath))
{
return 0;
}
else
if((fp == fopen(cMyFileName, "r")) == NULL)
return 0;
else
// else
//system( "dir *.log.1");
}
int main()
{
char cFilePath1[50] = "D://kcxp//log";
char cFileName1[30] = "ERR0001.log.1";
strcat(cFilePath1,"//");
TodayFileName();
strcat(cFilePath1,tmpbuf);
return 0;
}
写好后测试了一下,还行,不过后来又改了,就成现在这样了.
相关文章推荐
- C++中打开指定目录的函数
- 编写一个程序,首先用opendir函数打开用户指定的目录,然后调用readdir函数读取该目录内容
- C++删除目录和复制目录函数
- window下获取指定目录下面的所有文件名 c/c++
- android打开指定目录文件中的所有图片,只用于浏览
- 尝试为文件附加自动命名的数据库,但失败。已存在同名的数据库,或指定的文件无法打开或位于 UNC 共享目录中
- C++打开(弹出)指定路径文件夹
- C++打开文件夹并选中指定文件
- shell脚本:创建函数并指定目录进行下载
- 【编程语言】C++ 遍历指定目录下的文件
- 打开 删除指定目录下的word文档
- 常用函数之指定目录下查询文件
- C++实现Linux下遍历指定目录下的文件
- 【Linux编程】C/C++获取目录下文件或目录及linux中fork()函数详解(原创!!实例讲解)
- c#winform选择文件,文件夹,打开指定目录方法
- C++获取指定目录下的所有文件
- [C/C++]遍历目录下指定(任意)文件
- C++ (MFC)将字符串保存到指定目录下的文本中
- C/C++打开文件函数fopen和fopen_s用法的比较
- Windows 10快速在指定目录打开命令行