如何检查文件是否存在使用Win32程序? [英] How can we check if a file Exists or not using Win32 program?
本文介绍了如何检查文件是否存在使用Win32程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检查文件是否存在使用Win32程序?我正在为Windows Mobile应用程序工作。
How can we check if a file Exists or not using a Win32 program? I am working for a Windows Mobile App.
推荐答案
您可以调用 FindFirstFile
。
You can call FindFirstFile
.
这是我刚刚敲门的一个例子:
Here is a sample I just knocked up:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
int fileExists(TCHAR * file)
{
WIN32_FIND_DATA FindFileData;
HANDLE handle = FindFirstFile(file, &FindFileData) ;
int found = handle != INVALID_HANDLE_VALUE;
if(found)
{
//FindClose(&handle); this will crash
FindClose(handle);
}
return found;
}
void _tmain(int argc, TCHAR *argv[])
{
if( argc != 2 )
{
_tprintf(TEXT("Usage: %s [target_file]\n"), argv[0]);
return;
}
_tprintf (TEXT("Looking for file is %s\n"), argv[1]);
if (fileExists(argv[1]))
{
_tprintf (TEXT("File %s exists\n"), argv[1]);
}
else
{
_tprintf (TEXT("File %s doesn't exist\n"), argv[1]);
}
}
这篇关于如何检查文件是否存在使用Win32程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文