rtnMichael
Programmer
hey guys, I have certain folders I have to have for my program to run. I build char arrays to get the full path names of the folders to check with a subroutine if they exist. I have about 9-10 to check for, and the sub has redundant code checking for each individual folder. I want to send the names to an array so I can just do a loop and the sub will be cut down to two IF statements...maybe a bit of code to help.
Here's where I build the path for some of the folders and place them in char arrays:
RootPath is set by the user
static void BuildNeededPaths()
{
/* Build needed directory names.
*/
sprintf(TargetDir, "%s%s", RootPath, "NotSent/"
sprintf(WipDir, "%s%s", RootPath, "Wip/"
sprintf(PurgeDir, "%s%s", RootPath, "OkToPurge/"
sprintf(DcutokenDir, "%s%s", RootPath, "DcuTokenArch/"
...etc
}
static int CheckDirectories()
{
struct stat stat_buf;
/* Get the status information and make sure its a directory.
*/
if(stat(RootPath, &stat_buf))
{
LogIt(1,FLAGIT,"Can not stat %s - %s", RootPath, strerror(errno));
return(0); /* not found */
}
if(!(S_IFDIR & stat_buf.st_mode))
{
LogIt(1,FLAGIT,"%s is not a directory", RootPath);
return(0);
}
BOTH THESE IF'S GO ON TO CHECK THE REST OF THE FOLDERS...THAT'S A LOT OF REDUNDANT CODE
}
What would be the correct syntax to place the TargetDir, RootPath, etc... in an array I could use for the loop and pass through to the sub?
Thanks
M
Here's where I build the path for some of the folders and place them in char arrays:
RootPath is set by the user
static void BuildNeededPaths()
{
/* Build needed directory names.
*/
sprintf(TargetDir, "%s%s", RootPath, "NotSent/"
sprintf(WipDir, "%s%s", RootPath, "Wip/"
sprintf(PurgeDir, "%s%s", RootPath, "OkToPurge/"
sprintf(DcutokenDir, "%s%s", RootPath, "DcuTokenArch/"
...etc
}
static int CheckDirectories()
{
struct stat stat_buf;
/* Get the status information and make sure its a directory.
*/
if(stat(RootPath, &stat_buf))
{
LogIt(1,FLAGIT,"Can not stat %s - %s", RootPath, strerror(errno));
return(0); /* not found */
}
if(!(S_IFDIR & stat_buf.st_mode))
{
LogIt(1,FLAGIT,"%s is not a directory", RootPath);
return(0);
}
BOTH THESE IF'S GO ON TO CHECK THE REST OF THE FOLDERS...THAT'S A LOT OF REDUNDANT CODE
}
What would be the correct syntax to place the TargetDir, RootPath, etc... in an array I could use for the loop and pass through to the sub?
Thanks
M