Re: parsing directory



oswald.harry@xxxxxxxxx wrote:
hi all,
i am a newbie to c and learning by K&R..
i need to parse a folder in my system and create an array containing
the fully qualified names of all .png files in sorted order ,ie in
ascending order of filenames..i have been struggling for sometime..:-
( but i don't know how to open a directory when the dir name is
given as a string

ie i would call
myapp.exe F:\mycode\mypngfiles\

any advise ,pointers wd be most appreciated
thank you
hos.


Take a look at the functionality included in <dirent.h>. This header files declares functions to browse a directory and lists its content and is, if I recall correctly, also mentioned in the K&R book. However, I can't say for sure this functionality is available on MS Windows using the MS Visual C compiler. Maybe you'll need to find some WINAPI functions that mimic <dirent.h> behavior.

If you have the list of file, you only need to do a string comparison on the file extension. To be a 100% safe you should take a look at the MIME settings of the file because on Unix for example file extensions are not mandatory. This is however outside the scope of this discussion group.

- Jensen
.



Relevant Pages

  • Re: How many bytes per Italian character?
    ... Write the code to insert a new element in sorted order" and of 27 interviewees, 26 failed to do it, and the only one who got it right was a PhD candidate, and she struggled to get it. ... I can do it with both LRU optimization for lookup and sublinear insert performance for large lists without thinking too hard about it. ... If with list we mean array, I could do a kind of binary search to find the place of insertion, and then insert. ... If Dr. Newcomer's caching succeeds then he doesn't have to visit all previous K-1 elements. ...
    (microsoft.public.vc.mfc)
  • Re: Suggestions for benchmarks for work on TList.Sorting.
    ... > I suggest that the benchmarks for sorts that are intended for ... > having the start data already the reverse of sorted order. ... > The TList.Sort programmer should be aware that some lists ... TList.Sort shouldn't be dereferencing the pointers anyway as they may ...
    (borland.public.delphi.language.basm)
  • Suggestions for benchmarks for work on TList.Sorting.
    ... Please excuse me if the topics have already ... having the start data already the reverse of sorted order. ... The TList.Sort programmer should be aware that some lists ...
    (borland.public.delphi.language.basm)
  • Unable To Remove From Open With List
    ... I am running WinXP SP1 with all of the latest updates from MS Windows ... I am unable to remove applications from my Open With Lists by editing the ... remove it from the standard Registry key. ... given file extension but can NOT be found in the standard Registry keys: ...
    (microsoft.public.windowsxp.help_and_support)
  • Unable To Remove From Open With List
    ... I am running WinXP SP1 with all of the latest updates from MS Windows ... I am unable to remove applications from my Open With Lists by editing the ... remove it from the standard Registry key. ... given file extension but can NOT be found in the standard Registry keys: ...
    (microsoft.public.windowsxp.general)