Article View: comp.os.msdos.programmer
Article #4872Re: Bug in TC findfirst()/findnext()!
From: Bruce R. Williams
Date: Mon, 25 Feb 1991 22:21
Date: Mon, 25 Feb 1991 22:21
40 lines
2144 bytes
2144 bytes
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 <disclaimer.h>
> gordon@cerl.cecer.army.mil #include <clever_saying.h>
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
Technical Details
Message-ID:
<1991Feb25.152152.17353@hellgate.utah.edu>Path:
arc1-ca.pugleaf.net!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!bwilliamReferences:
<1991Feb25.192823.18224@ux1.cso.uiuc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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