1 / 4

Solving a problem: scandir and Unix ls

Solving a problem: scandir and Unix ls. Access all the entries in a directory, or selected entries ls *.cc, ls -l *, ls -lt foo.* process the entries in some way (add sizes, print, …) What is in a directory? ., .., files, subdirectories

kohana
Download Presentation

Solving a problem: scandir and Unix ls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Solving a problem: scandir and Unix ls • Access all the entries in a directory, or selected entries • ls *.cc, ls -l *, ls -lt foo.* • process the entries in some way (add sizes, print, …) • What is in a directory? • ., .., files, subdirectories • what is a file in Unix? What kind of resources are associated with a file? How do you create/remove a file from within a running program? • How are files and directories accessed from a program? • How is a directory tree backed-up to disk/tape? • What are the issues?

  2. Solving another problem: search for words • Web-based search engines • Search for “Titanic” + “Linux” in Alta vista • File-based search engines • What’s the file that has the reference to “elephants”? • What are the issues in the searches? • User’s perspective • Programmer’s perspective • What about approximate matches • search for “pincake” or “pancake” or “pancakes” or … • are approximate/fuzzy matches a good idea?

  3. Coping with transferable ownership • Factory creates a class, who deletes it? Foo * f = FooFactory::makeFoo(); f->doFooStuff(); delete f; • Why might this be a problem? What are alternatives? • Instead of using a Foo pointer, use a proxy, a class that stands in for a Foo pointer • looks like a Foo pointer, acts like a Foo pointer, but cleans up after itself (SmartStrings in sortall/cps 100): heap vs. stack allocation FooProxy f(FooFactory::makeFoo()); f->doFooStuff();

  4. Program parameters and errors • What are alternatives to large if/else chains to process argc and argv? • What are argc/argv used for? • What helper functions cope with arg parsing? • What’s wrong with if (argv[k] == “-f”) • Other options to getting info into program • How do you signal an error condition? • Files don’t open, times (wag) out of order, … • cerr << • other alternatives?

More Related