Created
April 26, 2025 00:40
-
-
Save evaporei/cf7e0eb0e871cdc585fde11d317fb922 to your computer and use it in GitHub Desktop.
List all entries of dir using win32
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
int main() { | |
WIN32_FIND_DATA findFileData; | |
HANDLE hFind = INVALID_HANDLE_VALUE; | |
LPCSTR directoryPath = "C:\\Users\\myusername\\Downloads\\*"; | |
hFind = FindFirstFile(directoryPath, &findFileData); | |
if (hFind == INVALID_HANDLE_VALUE) { | |
printf("FindFirstFile failed (%lu)\n", GetLastError()); | |
return 1; | |
} | |
do { | |
printf("%s\n", findFileData.cFileName); | |
} while (FindNextFile(hFind, &findFileData) != 0); | |
FindClose(hFind); | |
return 0; | |
} |
how to make it if your string ain't constant:
s := "C:\\Users\\evaporei\\*"
l := make([]u16, len(s) + 1)
for ch, i in s {
l[i] = u16(ch)
}
l[len(l) - 1] = 0
h_find = win32.FindFirstFileW(raw_data(l), &find_file_data)
Edit: oh I just found out there's a bunch of wide string utils here.
So the above can be achieved like:
s: cstring = "C:\\Users\\evaporei\\*"
w_s := win32.utf8_to_utf16(string(s), context.temp_allocator)
h_find = win32.FindFirstFileW(raw_data(w_s), &find_file_data)
delete(w_s, context.temp_allocator)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
same but in Odin: