Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Directory Name in One Folder

Status
Not open for further replies.

ty1975

Programmer
Nov 5, 2002
12
GB
I'm wondering anyone can tell me how to check the directory name under one folder. Basically, I need to check whether certain directory exists under one folder.

Thanks a lot. :)
 
use the FindFirstFile()function to find the directory.
Hope this helps or find the Help from MSDN.
 
Unix/Linux.
Very basic , should get you started.
Usage: progname / "tmp", for example.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>


int main(int argc, char *argv[]) {
int y;
char *ptr;
DIR *mydir;
struct dirent *mydpt;

if (argc != 3) {
printf(&quot;Wrong # args, need parent directory name(1) and subdirectory name(2).\n&quot;);
exit(1);
}

if ( (mydir = opendir(argv[1])) != NULL) {
while ( (mydpt = readdir(mydir)) != NULL) {
if ( (y = strcmp(mydpt->d_name, argv[2])) == 0) {
printf(&quot;%s found in %s\n&quot;, mydpt->d_name, argv[1]);
closedir(mydir);
return 0;
}
}
}
closedir(mydir);
printf(&quot;Could not find %s\n&quot;, argv[2]);
return 1;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top