如何使用VC++检查C:\驱动器中是否存在文件? [英] How to check whether a file exists in C:\ drive using VC++?

查看:25
本文介绍了如何使用VC++检查C:\驱动器中是否存在文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查 C 盘中是否存在文件..?谁能告诉我怎么做?

I want to check a file is present in C drive or not..? can any one tell me how ?

更新:

出现错误,我使用的是 VC++ 2008

I got errors, I am using VC++ 2008

#include "stdafx.h" 
#include <stdio.h> 
int main(int argc, _TCHAR argv[]) 
{ 
    FILE * f = fopen("C:\\Program Files (x86)\\flower.jpeg"); 
    if (f == NULL) { 
        file_exists = FALSE:
    } else { 
        file_exists = TRUE; 
        fclose(f);
    } 
    return 0;
}

更新 2

尝试从 链接中剪切和粘贴代码时示例如下:

#include "stdafx.h" 
#include <windows.h> 
#include "Shlwapi.h" 
int tmain(int argc, _TCHAR argv[]) 
{ 
    // Valid file path name (file is there). 
    TCHAR buffer_1[ ] = _T("C:\\TEST\\file.txt"); 
    TCHAR *lpStr1; 
    lpStr1 = buffer_1; 

    // Return value from "PathFileExists". 
    int retval;

    // Search for the presence of a file with a true result.
    retval = PathFileExists(lpStr1); 
    return 0;
} 

我收到此错误:

files.obj : error LNK2019: unresolved external symbol __imp__PathFileExistsW@4 referenced in function _wmain 

推荐答案

如果您提到 C 驱动器,我假设您可以使用 Windows API,如果可以的话 PathFileExists(LPCTSTR) 会帮你

Given you mention C drive, I'm assuming you can use the Windows API, if so PathFileExists(LPCTSTR) will do you

这篇关于如何使用VC++检查C:\驱动器中是否存在文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆