判断状态#includeio.hint _access( constchar*path,intmode);返回值: 0表示允许访问,-1表示禁止访问CreateFile HANDLE hFile=CreateFile("c://123.bmp",GENERIC_WRITE|GENERIC_READ,OPEN_EXISTING, //OPEN_EXISTING FILE_ATTRIBUTE_NORM
判断状态
#include<io.h>
int _access( constchar*path,intmode);
返回值: 0表示允许访问,-1表示禁止访问
CreateFile
HANDLE hFile=CreateFile("c://123.bmp",GENERIC_WRITE|GENERIC_READ,
OPEN_EXISTING, //OPEN_EXISTING
FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE)//标示文件不存在
删除
BOOL DeleteFile(LPCSTR szFileName);
int SHFileOperation(LPSHFILEOPSTRUCT);
新建
WINBASEAPI
HANDLE
WINAPI
CreateFileW(
LPCWSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);
CreateFile("123.txt", GENERIC_WRITE|GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
#include <stdio.h>
fopen("123.txt","wb+");
复制
CopyFile
SHFileOperation
清空文件内容
SetFilePointer(hFile,0,NULL,FILE_BEGIN);
SetEndOfFile(hFile);
HANDLE hFile=CreateFile("c://123.bmp",GENERIC_WRITE|GENERIC_READ,
,TRUNCATE_EXISTING,//已清空文件的方式打开
FILE_ATTRIBUTE_NORMAL,NULL);
获取文件长度
1、
#include <stdio.h>
FILE *fp=fopen("c:/123.bmp",rb);
fseek(fp,0,SEEK_END);//文件指针移到尾
ulong flen=ftell(fp);//文件长度
fseek(fp,0,SEEK_SET);//移回来
2、
#include <stdio.h>
#include <io.h>
FILE *fp=fopen("c:/123.bmp",rb);
ulong flen=filelength(fileno(fp));
3、
#include <sys/stat.h>
struct _stat info;
_stat(filepath, &info);
int size = info.st_size;
4、
HANDLE hFile=CreateFile("c://123.bmp",GENERIC_WRITE|GENERIC_READ,
,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
DWORD dwflen=GetFileSize(hFile,NULL);
CloseHandle(hFile);
mode value
00
检测是否存在
02
写权限
04
读权限
06
读写权限
【文章转自防cc http://www.558idc.com/gfcdn.html 复制请保留原URL】