我们如何使用 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
.
这是我刚刚敲出的样本:
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]
"), argv[0]);
return;
}
_tprintf (TEXT("Looking for file is %s
"), argv[1]);
if (fileExists(argv[1]))
{
_tprintf (TEXT("File %s exists
"), argv[1]);
}
else
{
_tprintf (TEXT("File %s doesn't exist
"), argv[1]);
}
}
这篇关于我们如何使用 Win32 程序检查文件是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文