Home > Back-end >  C how to get all of the files in specified folder full path?
C how to get all of the files in specified folder full path?

Time:11-29

Such as E: \ picture folder there are three images 1. JPG 2. JPG 3. JPG
Want to get the path of the 3 picture
E: \ picture \ 1. JPG
E: \ picture \ 2. JPG
E: \ picture \ 3. JPG

Visual studio2017 debugx64
Online to find an error, just contact c gagarin soon, I won't change, and a can directly use the code, thank you

CodePudding user response:

It seems that your file path is Windows, development IDE is visual studio, I'll get a Windows version, only supplies the reference:
 # include & lt; IO. H> 
#include
#include

# define MAX_LEN 4096

Int main (void)
{
Char root []="E: \ \ picture";
Struct _finddata_t file;
Intptr_t hFile;
Char buf [MAX_LEN];

If (_chdir (root))
{
Printf (" failure: open the folder % s/n ", the root).
return 1;
}

HFile=_findfirst (" *.jpg ", & amp; The file);
While (_findnext (hFile, & amp; The file)==0)
{
Sprintf_s (buf MAX_LEN, "% s \ \ % s", root, the file. The name).
Printf (" % s \ n ", buf);
}

return 0;
}
  • Related