Windows编程 之临时文件 (笔记)
来源:互联网 发布:淘宝图片用什么软件 编辑:程序博客网 时间:2024/06/04 23:25
1. 函数说明
1.1 GetTempFileName
创建一个临时文件,并返回临时文件的名字
【1】 lpPathName 路径名
【2】lpPrefixString 前缀
【3】uUnique 是否唯一,0为唯一,否则不是。当设置为0时,会创建一个空文件,否则只是返回一个文件名
【4】 返回的文件名,格式为 <path>\ <pre><uuuu>.TMP
UINT WINAPI GetTempFileName( _In_ LPCTSTR lpPathName, _In_ LPCTSTR lpPrefixString, _In_ UINT uUnique, _Out_ LPTSTR lpTempFileName);
2. 代码
/* * FileName: SystemTempFile.cpp * Author: JarvisChu * Date: 2012-11-14 */#include <stdio.h>#include <windows.h>#include <tchar.h> //switchs for the program//notice: do not open more than one //#define TEMP_FILE//#define PATH //#define FILE_TIME#define FILE_ATTRIBUTE#define BUFF_SIZE 256int main(){//--------------------------------------------------------#ifdef TEMP_FILEprintf("--------Temp File----------------\n");DWORD nLen;TCHAR szFileName[BUFF_SIZE];TCHAR szLongPathBuff[BUFF_SIZE];TCHAR szShortPathBuff[BUFF_SIZE];GetTempFileName(_T("E:/Programming"), //the directory to create the temp file. '.' represents the current directory_T("jc"), //the prefix string of the temp file0,szFileName );//the szFileName can be string like "./jc258.tmp" or "./jc454.tmp"//and the file named "jc258.tmp" or "jc454.tmp" have been created in the current directoryprintf(_T("TempFile Name: %s\n"),szFileName); GetFullPathName(szFileName,BUFF_SIZE,szLongPathBuff,NULL);printf("FullPathName: %s\n",szLongPathBuff); // E:/Programming\jc5EC.tmpnLen = lstrlen(szLongPathBuff);GetShortPathName(szLongPathBuff,szShortPathBuff,nLen);printf("ShortPathName: %s\n",szShortPathBuff);// E:\PROGRA~2\jc5EC.tmp#endif//--------------------------------------------------------#ifdef FILE_TIMEprintf("--------File Time----------------\n");//GetFileTime()HANDLE hFile;FILETIME ftCreate,ftAccess,ftWrite,ftLocal;SYSTEMTIME stCreate;hFile = CreateFile(_T("C:/jarvischu.txt"),GENERIC_READ|GENERIC_WRITE,NULL,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);GetFileTime(hFile,&ftCreate,&ftAccess,&ftWrite);// Convert the last-write time to local time. FileTimeToLocalFileTime(&ftWrite, &ftLocal); // Convert the local file time from UTC to system time. FileTimeToSystemTime(&ftLocal, &stCreate);HANDLE hConsoleOut = CreateFile("CONOUT$",GENERIC_WRITE,NULL,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);TCHAR szBuf[BUFF_SIZE];DWORD nLen,nWrite; // Build a string showing the date and time. wsprintf(szBuf,"%02d/%02d/%d %02d:%02d\n", stCreate.wDay, stCreate.wMonth,stCreate.wYear, stCreate.wHour, stCreate.wMinute);nLen = lstrlen(szBuf);WriteConsole(hConsoleOut,szBuf,nLen,&nWrite,NULL);#endif//--------------------------------------------------------#ifdef PATHprintf("--------FullPath & ShortPath----------------\n");DWORD nLen;TCHAR szLongPathBuff[BUFF_SIZE];TCHAR szShortPathBuff[BUFF_SIZE];GetFullPathName(_T("E:/Programming/jarvischu.txt"),BUFF_SIZE,szLongPathBuff,NULL);printf("FullPathName: %s\n",szLongPathBuff); //E:\Programming\jarvischu.txtnLen = lstrlen(szLongPathBuff);GetShortPathName(szLongPathBuff,szShortPathBuff,nLen);printf("ShortPathName: %s\n",szShortPathBuff);//E:\PROGRA~2\JARVIS~1.TXT#endif//--------------------------------------------------------#ifdef FILE_ATTRIBUTEprintf("--------File Attribute----------------\n");DWORD dwAttr;dwAttr = GetFileAttributes("E:/Programming/jarvischu.rar");if(dwAttr != -1) // -1 stands for file_not_exists or no rights to access the file{if( dwAttr & FILE_ATTRIBUTE_ARCHIVE){printf("File is Archived!\n");}if (dwAttr & FILE_ATTRIBUTE_NORMAL){printf("File is Normal!\n");}}#endifreturn 0;}
- Windows编程 之临时文件 (笔记)
- UNIX环境编程学习笔记(14)——文件I/O之临时文件
- 《UNIX环境高级编程》笔记--临时文件
- 巧用WINDOWS脚本语言删除临时文件 (转载)
- Linux编程-标准IO(4)-临时文件
- Python tempfile模块学习笔记(临时文件)
- WINDOWS删除临时文件
- Windows 创建临时文件
- 获取Windows 临时文件目录 和临时文件
- .net开发笔记之七:定时清除临时文件
- Linux C编程--临时文件
- windows编程学习笔记之定时器
- 《MFC Windows编程》之文档视图笔记
- windows 核心编程 笔记之 进程
- 雅阁学习笔记之windows编程
- UNIX之临时文件
- oracle学习笔记(3)(数据文件,日志文件,临时文件)
- 关于windows的IE临时文件
- 随想录(写给那些学校不是985、211的同学们)
- 基于lucene搜索引擎的Hibernate Search,官方文档翻译
- 简明 Vim 练级攻略
- 字符串处理函数
- 多进程和多线程比较
- Windows编程 之临时文件 (笔记)
- XStream快速起步 简单方便实现序列化(XML和JSON)
- 四步走让错误变成你成功的垫脚石
- Unity bundle的制作和使用
- win8中mac虚拟机网络连接
- IPC,一直被人们忽视的“东西”。
- Android 开发之多线程处理、Handler详解
- 超全的JS重新加载当前页面的几种方式
- jacob合并多个word文件和插入分页符