Open files and write to them using multi threading in C language on windows

hello guys

I have large number of files about two 2000 , and I’m trying to open each of them and write “hello world” , I did it but it is too slow , I need to make it multi threaded .help :cry:

thank you

Could you provide information as to how you’re trying to achieve this? What have you tried so far? What were your issues?

first get a list of the file :

#include <Windows.h>

vector get_all_files_names_within_folder(string folder)
{
vector names;
string search_path = folder + “/.”;
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile(search_path.c_str(), &fd);
if(hFind != INVALID_HANDLE_VALUE) {
do {
// read all (real) files in current folder
// , delete ‘!’ read other 2 default folder . and …
if(! (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) {
names.push_back(fd.cFileName);
}
}while(::FindNextFile(hFind, &fd));
::FindClose(hFind);
}
return names;
}

then open the file and write hello world.

“hello world”>>names

for multi threadeing you need thread :

thread t1

and set t1 for funection (list or open file or write file or all and …)

if you work on windows use powershell .
or use autoit .its so easy.
example for write file

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.