How to search curent directory for txt file
How would I make a function to look for any files that start with the word image
and load all text files that start with that name?
This is so I can load my info about every image
example
image file name
image width
image height
image transparent color
this will be saved for every single image so I dont have to type it in every time for every image I use.
for some reason MS examplse for FindFirstFile and FindNextFile are not working they just crash on me. any onw know why?
Quote:Original post by kingpinzs
for some reason MS examplse for FindFirstFile and FindNextFile are not working they just crash on me. any onw know why?
They work find for me plug and play.
#define _WIN32_WINNT 0x0400#include <windows.h>#include <stdio.h>const char* fileName = "YourFile.Ext";int main(int argc, char *argv[]){ WIN32_FIND_DATA FindFileData; HANDLE hFind; printf ("Target file is %s.\n", fileName ); hFind = FindFirstFile(fileName , &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError ()); return (0); } else { printf ("The first file found is %s\n", FindFileData.cFileName); FindClose(hFind); return (1); }}
Just type in the file name you are looking for in the variable fileName and it should work.
only one question how would i find all files with name image*.txt
so it would load like 10 files that start with image and anything after and there all txt files
so it would load like 10 files that start with image and anything after and there all txt files
you can use this:
or that:
#include <stdio.h>#include <io.h> int main(int argc,char *argv[]){ char **flist = findfiles(argv[1]); char **s = flist; while (*s) { printf("%s\n",*s); s++; } free(flist); }
or that:
#include <stdio.h>#include <io.h>int main(int argc,char *argv[]){ struct _finddata_t c_file; long File; if((File = _findfirst( "*.c", &c_file )) == -1L) printf("No %s files in current directory!\n", argv[1]); else { printf("%s\n", c_file.name); while( _findnext( hFile, &c_file ) == 0 ) { printf("%s\n", c_file.name); } _findclose(File); }}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement