关于读取某路径下文件的问题
时间:2008-05-26 11:10:12
来源:论坛整理 作者: 编辑:chinaitzhe
而在文件目录下D:\c 项目\杂文集\win32-推磁球\res\wma有许多wma文件
怎么在WIN32工程下将这些文件名读取到程序string里?
而不是自己手动依次写路径,比如:
mciSendString("play D:\c 项目\杂文集\win32-推磁球\res\wma\BEYOND-情人.wma",0,0,0);
网友回复:用CFileFind。
网友回复:
- C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ Searches a directory for a file or subdirectory with a name that matches a specific name. To specify additional attributes to use in a search, use the FindFirstFileEx function. To perform this operation as a transacted operation, use the FindFirstFileTransacted function. HANDLE WINAPI FindFirstFile( __in LPCTSTR lpFileName, __out LPWIN32_FIND_DATA lpFindFileData ); Continues a file search from a previous call to the FindFirstFile or FindFirstFileEx function. BOOL WINAPI FindNextFile( __in HANDLE hFindFile, __out LPWIN32_FIND_DATA lpFindFileData ); Client Requires Windows Vista, Windows XP, or Windows 2000 Professional. Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. Header Declared in WinBase.h; include Windows.h. Library Use Kernel32.lib. DLL Requires Kernel32.dll. Unicode Implemented as FindNextFileW (Unicode) and FindNextFileA (ANSI).
网友回复:API调用:
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind = INVALID_HANDLE_VALUE;
char DirSpec[MAX_PATH]; // directory specification
DWORD dwError;
printf ("Target directory is %s.\n", argv[1]);
strncpy (DirSpec, argv[1], strlen(argv[1]) 1);
strncat (DirSpec, "\\*", 3);
hFind = FindFirstFile(DirSpec, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is %u\n", GetLastError());
return (-1);
}
else
{
printf ("First file name is %s\n", FindFileData.cFileName);
while (FindNextFile(hFind, &FindFileData) != 0)
{
printf ("Next file name is %s\n", FindFileData.cFileName);
}
dwError = GetLastError();
FindClose(hFind);
if (dwError != ERROR_NO_MORE_FILES)
{
printf ("FindNextFile error. Error is %u\n", dwError);
return (-1);
}
}
return (0);
}
网友回复:那是MFC的吧,有WIN32的方法吗
关键字:读取,路径,文件,问题,
上一篇:C 和VC 的区别在哪里?
下一篇:下面没有链接了











文章评论
共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面