如何根据文件名获取到文件在windows下的全路径?

shuguangyihao408 2013-07-03 11:37:39
本人很急,麻烦会弄的大神,给个思路或者指导意见呀
...全文
229 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gg606 2013-07-04
  • 打赏
  • 举报
回复
可以吗?得是当前路径下的吧?不同文件夹下的文件可以同名的呀
shen_wei 2013-07-04
  • 打赏
  • 举报
回复
	WCHAR buffer[BUFSIZ] = {0}; 
	LPWSTR lpPart[BUFSIZ]={0};

	// Retrieve a full path name for a file.  The file does not need to 
	// exist.
	 GetFullPathName(_T("Big5.dat"),
		BUFSIZ,
		buffer,
		lpPart);
numen27 2013-07-04
  • 打赏
  • 举报
回复
GetFullPathName function Retrieves the full path and file name of the specified file. DWORD WINAPI GetFullPathName( _In_ LPCTSTR lpFileName, _In_ DWORD nBufferLength, _Out_ LPTSTR lpBuffer, _Out_ LPTSTR *lpFilePart ); Parameters lpFileName [in] The name of the file. This parameter can be a short (the 8.3 form) or long file name. This string can also be a share or volume name. In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see Naming a File. nBufferLength [in] The size of the buffer to receive the null-terminated string for the drive and path, in TCHARs. lpBuffer [out] A pointer to a buffer that receives the null-terminated string for the drive and path. lpFilePart [out] A pointer to a buffer that receives the address (within lpBuffer) of the final file name component in the path. This parameter can be NULL. If lpBuffer refers to a directory and not a file, lpFilePart receives zero.
赵4老师 2013-07-03
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
char cmdstr[1024];
char d;
char fn[256];
int main() {
 printf("Enter a filename:");fflush(stdout);
 scanf("%[^\n]",fn);
 sprintf(cmdstr,"dir /b /a-d /s \"%c:\\%s\" >d:\\filesinall.txt",'c',fn);
 system(cmdstr);
 for (d='d';d<='z';d++) {
  sprintf(cmdstr,"dir /b /a-d /s \"%c:\\%s\" >>d:\\filesinall.txt",d,fn);
  system(cmdstr);
 }
 system("type d:\\filesinall.txt");
 return 0;
}
深圳老码农 2013-07-03
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
#include <stdio.h>
#include <stdlib.h>
char cmdstr[1024];
char d;
char fn[256];
int main() {
 printf("Enter a filename:");fflush(stdout);
 scanf("%[^\n]",fn);
 sprintf(cmdstr,"dir /b /a-d /s \"%c:\\%s\" >d:\\filesinall.txt",'c',fn);
 system(cmdstr);
 for (d='d';d<='z';d++) {
  sprintf(cmdstr,"dir /b /a-d /s \"%c:\\%s\" >>d:\\filesinall.txt",d,fn);
  system(cmdstr);
 }
 system("type d:\\filesinall.txt");
 return 0;
}
你这个不好用啊
shuguangyihao408 2013-07-03
  • 打赏
  • 举报
回复
大神留个联系方式呀,能不能帮我解决个小问题,有酬谢

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧