S
S
Sasha2942018-10-12 01:09:30
C++ / C#
Sasha294, 2018-10-12 01:09:30

How can I substitute a different path to the disk through the FindFirstFileW method?

TCHAR szFileName[255];
  GetModuleFileName(NULL, szFileName, 255);// диск  szFileName

  WIN32_FIND_DATAW wfd;
  
  HANDLE const hFind = FindFirstFileW(L"D:\\report\\*", &wfd); //место д подставить другой

  setlocale(LC_ALL, "");

  if (INVALID_HANDLE_VALUE != hFind)
  {
    do
    {
      std::wcout << &wfd.cFileName[0] << std::endl;
    } while (NULL != FindNextFileW(hFind, &wfd));

    FindClose(hFind);
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Other planet, 2018-10-12
@BadElectrician

Use a double array and loop
char path[3][256]; char *ppath[3];
path[0]="c:\catalog\...";
...
path[3]="f:\....";
for(int i =0;i!=3;i++){
pparh[i]=path[i];
h = _findfirst(ppath[i],&info);
....
}

S
Sumor, 2018-10-12
@Sumor

If you are using TCHAR, then FindFirstFile should be used instead of FindFirstFileW.
TCHAR is, depending on the preprocessor settings, either char or wchar_t.
Accordingly, the WinApi functions, depending on this setting, choose which version of ansi or unicode to call.
By convention, you can use char, call GetModuleFileNameA and FindFirstFileA.
Or, if you only have unicode: use wchar_t, call GetModuleFileNameW and FindFirstFileW.
Or, as most do, use the TCHAR generic type, call GetModuleFileName and FindFirstFile. The compiler will choose which version of ansi or unicode to use.
Unfortunately, Microsoft did not come up with tcout for the console, so you need to select the console depending on the preprocessor parameter, for example like this:

#if defined(UNICODE) || defined(_UNICODE)
#define tcout std::wcout
#else
#define tcout std::cout
#endif

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question