Hello I want to create a program that will search for a folder in the folder that exe is running. If here is a folder called user it will search for a file called currentuser.dat in that folder. If not then it will create that folder and create currentuser.dat file and write to it. I found some articles about using third party or windows functions but i dont want. How can i do that with std::filesystem
Note there may be a file (not folder) called "user" in the current directory, in which case this little demo also quietly fails and does nothing.
(if you do want to search, the API to call is directory_iterator: https://en.cppreference.com/w/cpp/filesystem/directory_iterator ) but remember that result of any filesystem search is outdated the moment you look at it. The search will tell you there is no folder called "user", but by the time your program gets to the next line and attempts creating it, another program may have created it.
Actually that program is creating the "user" directory off the current working directory, so if the working directory is the directory where your .exe is located then "user" will be created where you expect it to be created.
When running the program from many IDE the current working directory will quite often be the directory containing the "project" files.
right, that program expects you ran it directly, not through IDE or with otherwise swapped current working directory. Picking up a stable place for user settings that don't depend on how you run he program is a little more work (on Windows I'd consider making a folder in C:\Users\yourname\AppData\Local)