I successfully created a directory or folder and I also managed to create a file in that directory but how can create a directory and a file in the user's appdata local if I don't know what is their username or their user folder name? thanks!
I used codeblocks
#include <sys/stat.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void main()
{
int check;
char* dirname = "C:/Pyromagne";
check = mkdir(dirname);
FILE* fp;
fp = fopen("C:/Pyromagne/test.pyr", "w+");
fputs("Pyromagne\n", fp);
fputs("qwertyuiop", fp);
fclose(fp);
FILE* ffpp;
char user[25];
char pass[25];
char uuser[25];
ffpp = fopen("C:/Pyromagne/test.pyr", "r");
strcpy(uuser, fgets(user, 255, (FILE*)ffpp));
printf("%s\n", uuser);
strcpy(uuser, fgets(user, 255, (FILE*)ffpp));
printf("%s\n", uuser);
fclose(ffpp);
}
SHGetKnownFolderPathobtains the Unicode path to AppData, Documents, etc.KNOWNFOLDERIDfor"C:\Users\MyName\AppData\Local"isFOLDERID_LocalAppDataThis function needs additional libraries for
CoTaskMemFree,KNOWNFOLDERID, andSHGetKnownFolderPathUsing MinGW, 64-bit, gcc version 4.8.3,
SHGetKnownFolderPathdoes not appear to be inlibshell32.a. The command linenm libshell32.adoes not list this function either. So in MinGW, we have to load this function manually as follows:Additionally, you can use
getenvor_wgetenv(Unicode version)To add the libraries in Code::Blocks, click Menu -> Settings -> Compiler, it should bring up this window:
Then click the "Add" button, find MinGW installation folder, the libraries should be at
You can figure out which libraries you need by looking at documentation for the function. For example
SHGetKnownFolderPathsays it needs "shell32.lib" (for Visual Studio) MinGW uses "libshell32.a" instead.