TheObserver
Programmer
I'm using the following code in my application to get a listing of a directory's contents:
main(argc,argv)
int argc;
char *argv[];
{
DIR *dirp;
int i;
struct dirent *direntp;
//check our arguments and make sure we have enough to operate
if ( argc < 2 )
{
if(consoleout)
{
printf("\n"
;
printf("Usage: \n"
;
}
exit(1);
}
dirp = opendir( argv[1] );
if( dirp == NULL )
{
//we got a blank
if(consoleout)
{
printf("\nError opening input file directory.\n"
;
}
exit(1);
}
else
{
while ( (direntp = readdir( dirp )) != NULL )
{
if((direntp->d_name != "."
&& (direntp->d_name != ".."
)
{
printf("filename: %s\n", direntp->d_name);
}
}
closedir(dirp);
return 0;
}
The problem is, with this code I only get partial filenames, at best. For instance, I have a directory full of files and this code only returns CC.CCC (two chars, the period, and the extension suffix). If I run this with another directory that contains only one file, I might get a different pattern altogether...there seems to be no rhyme or reason to which characters it is leaving off, except that they seem to only be missing characters from the front of the filenames.
Thanks for your time.
main(argc,argv)
int argc;
char *argv[];
{
DIR *dirp;
int i;
struct dirent *direntp;
//check our arguments and make sure we have enough to operate
if ( argc < 2 )
{
if(consoleout)
{
printf("\n"
printf("Usage: \n"
}
exit(1);
}
dirp = opendir( argv[1] );
if( dirp == NULL )
{
//we got a blank
if(consoleout)
{
printf("\nError opening input file directory.\n"
}
exit(1);
}
else
{
while ( (direntp = readdir( dirp )) != NULL )
{
if((direntp->d_name != "."
{
printf("filename: %s\n", direntp->d_name);
}
}
closedir(dirp);
return 0;
}
The problem is, with this code I only get partial filenames, at best. For instance, I have a directory full of files and this code only returns CC.CCC (two chars, the period, and the extension suffix). If I run this with another directory that contains only one file, I might get a different pattern altogether...there seems to be no rhyme or reason to which characters it is leaving off, except that they seem to only be missing characters from the front of the filenames.
Thanks for your time.