Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!samsung!uakari.primate.wisc.edu!caen!hellgate.utah.edu!peruvian.utah.edu!bwilliam From: bwilliam%peruvian.utah.edu@cs.utah.edu (Bruce R. Williams) Newsgroups: comp.os.msdos.programmer Subject: Re: Bug in TC findfirst()/findnext()! Keywords: tc,bug,find,findfirst,findnext Message-ID: <1991Feb25.152152.17353@hellgate.utah.edu> Date: 25 Feb 91 22:21:51 GMT References: <1991Feb25.192823.18224@ux1.cso.uiuc.edu> Organization: University of Utah CS Dept Lines: 40 In article <1991Feb25.192823.18224@ux1.cso.uiuc.edu> gordon@osiris.cso.uiuc.edu (John Gordon) writes: > > I submit the following program: ... > According to the _Turbo_C_Bible_, calls to findfirst() and findnext() >are supposed to return filenames that match *both* the given path *and* the >given attribute. However, the above program, which clearly specifies the >*directory* attribute (FA_DIREC), finds both directories *and* plain files. >Anyone have any comments/fixes/etc? >John Gordon >Internet: gordon@osiris.cso.uiuc.edu #include > gordon@cerl.cecer.army.mil #include Having just written a "new and improved" dir, I came across the same behavior. Fortunately, it only occurs in this one case--using the FA_DIREC attrib alone. One way around it would be to make a change like: while(findnext(&fileinfo) == 0) /* continue scanning for subdirs */ if (fileinfo.ff_attrib == FA_DIREC) printf("%s\n", fileinfo.ff_name); One other change you'll be wanting to make in your code: The result of getcwd() already ends with \ if you are in the root directory. So.. getcwd(path, 250); if (path[strlen(path)-1] == '\\') strcat(path, "*.*"); else strcat(path, "\\*.*"); Good Luck! -Bruce Bruce R. Williams "The most beautiful thing we can experience University of Utah is the mysterious. It is the source of all (bwilliam@peruvian.utah.edu) true art and science." -Albert Einstein