Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

How to search curent directory for txt file

This topic is 4698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
you can use this:

#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);
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by bjogio
you can use this:
*** Source Snippet Removed ***
or that:
*** Source Snippet Removed ***


it worked perfectly exactley what I needed thanks so much.

Thanks for every ones help it lead me in the roght direction and helped me learn alot I thank you very much

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!