Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

I. Exercises > 13. Directory Operations

Chapter 13. Directory Operations

13.1. Write a program that reports the number of files in the current directory. Don’t count special files . or .., but count the “hidden” files. (Answer to Exercise 13.1)

13.2. Modify your answer to Exercise 13.1 to also report the sum of all the file sizes (but don’t try to get the sizes of subdirectories). (Answer to Exercise 13.2)

13.3. Write a program that looks in the current working directory and creates a columnar report of all files, their sizes, and whether they are readable, writeable, and executable. Use opendir and a while loop. Your report might look like this:

Name                                 Size   R W E
-------------------------------------------------
.DS_Store                            6148   x x x
.Trashes                               68     x x
birthdays.db                        16384   x x
cores                                  68   x x x
Desktop                               102   x x x

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint