这可能是一个新手问题,所以我提前道歉。我在C方面不是很有经验 我有这个代码
#include <windows.h>
#include <locale.h>
void scanfiles(wchar_t *wstart_path)
{
WIN32_FIND_DATA fdFile;
HANDLE hFind = NULL;
// file mask *.* to find everything
size_t mlen = wcslen(wstart_path) + 5;
wchar_t fsbuf[mlen];
swprintf_s(fsbuf,mlen,L"%ls\\*.*",wstart_path);
if((hFind = FindFirstFileW(fsbuf, &fdFile)) == INVALID_HANDLE_VALUE)
{
wprintf(L"Path not found: [%ls]\n", wstart_path);
return;
}
size_t sbufsize = 256;
wchar_t *s = (wchar_t*)malloc(sbufsize*sizeof(wchar_t));
do
{
// FindFirstFile will return "."
// and ".." as the first two directories
if(wcscmp(fdFile.cFileName, L".") != 0
&& wcscmp(fdFile.cFileName, L"..") != 0)
{
mlen = wcslen(wstart_path) + wcslen(fdFile.cFileName) + 2;
if (mlen > sbufsize) {
s = (wchar_t*)calloc(mlen,sizeof(wchar_t));
wmemset(s,L'\0',mlen);
}
else {
wmemset(s,L'\0',sbufsize);
}
//Build up our file path using the passed in
//wstart_path and the file/foldername we just found:
wsprintf(s, L"%ls\\%ls\n", wstart_path, fdFile.cFileName);
//Is the entity a File or Folder?
if(fdFile.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY)
{
}
else {
wprintf(L"%s\n",s);
}
}
} while(FindNextFileW(hFind, &fdFile)); //Find the next file.
free(s);
FindClose(hFind);
return;
}
int main(int argc, char *argv[])
{
setlocale(LC_CTYPE,"RUS");
scanfiles(L"D:\\testdir");
return 0;
}
我在D:\ testdir中有一个名为“比赛_исправлено.doc”的文件 我的程序给了我以下输出:
D:\testdir\_исправлено.doc
我该怎么做才能获得全名?我该如何改进我的计划?如果我不仅要打印它而且还要写一个文本文件的路径怎么办?感谢。