Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucsd!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!uunet!mcsun!ukc!axion!planet!prk From: prk@planet.bt.co.uk (Peter Knight) Newsgroups: comp.os.os2.programmer Subject: Re: Need C segment to get directory on OS2 Message-ID: Date: 21 Aug 90 12:31:37 GMT References: Sender: usenet@planet.bt.co.uk (Usenet News Manager) Organization: RT743, BT Research Labs, Martlesham Heath, Ipswich, UK. Lines: 41 gould@pilot.njin.net (Brian Jay Gould) writes: >I know this is lazy, but I have no intention of becoming an OS/2 programmer. >Could someone please suggest a code segment that returns the first filename >in a directory? I'd like to get as the return, the oldest file in the >directory. No HPFS in this case. >My eternal thanks to anyone who helps. >-- >************************************************* >* Brian Jay Gould - Professional Brain-stormer * >************************************************* { FILEFINDBUF buf; DosFindFirst ("*.*",HDIR_SYSTEM, FILE_read_docu_for_options, &buf,sizeof(buf),1,0); printf ("%s",buf.achName); } -- This code should do the trick. Remember to do a #define INCL_DOSFILEMGR to get the right include files included. The first parameter is the file spec so you can use , for example "c:\\*.*", etc, here. For the file options, you have to decide what you want. This system call is capable of reading hiddens, etc, so you might normally use FILE_NORMAL ie files that "dir" can find. Remember, this does not return the oldest file. You cannot get this information, as if a deleted file is written over, its place may be used by a new file. Incidentally, this code is virtually identical to the MS-DOS int 21/4eh system call. Peter Knight BT Research #inlcude