[Working on ch20 John Goerzen **20071017173425] { hunk ./en/ch20-systems.xml 22 - We will alert you to OS-specific code where it occurs. Most of the - example sessions with &ghci; in this chapter require Linux, MacOS X, or - the Cygwin environment for Windows. + However, we will be focusing on the POSIX environment for much of the + chapter. POSIX is a standard for Unix-like operating systems such as + Linux, FreeBSD, MacOS X, or Solaris. Windows does not support POSIX by + default, but the Cygwin environment provides a POSIX compatibility layer + for Windows. hunk ./en/ch20-systems.xml 55 + + Directory and File Information + + The System.Directory module contains quite a few + functions that can be used to obtain information from the filesystem. + You can get a list of files in a directory, rename or delete files, + copy files, change the current working directory, or create new + directories. System.Directory is portable and works + on any platform where GHC itself works. + + + The library + reference for System.Directory provides a + comprehensive list of the functions available. Let's use &ghci; to + demonstrate a few of them. Most of these functions are straightforward + equivolents to C library calls or shell commands. + + &dir.ghci:setdir; + + Here we saw commands to change the current working directory and obtain + the current working directory from the system. These are similar to + the cd and pwd commands in the + POSIX shell. + + &dir.ghci:contents; + + getDirectoryContents returns a list for every item + in a given directory. Note that on POSIX systems, this list normally + includes the special values "." and + "..". You will usually want to filter these out + when processing the content of the directory, perhaps like this: + + &dir.ghci:contents2; + + You can also query the system about the location of certain + directories. This query will ask the underlying operating system for + the information. + + &dir.ghci:query; + + + + Program Termination + + Developers often write individual programs to accomplish particular + tasks. These individual parts may be combined to accomplish larger + tasks. A shell script or another program may execute them. The + calling script often needs a way to discover whether the program was + able to complete its task successfully. Haskell automatically + indicates a non-successful exit whenever a program is aborted by an + exception. + + However, you may need more fine-grained control over the + exit code than that. Perhaps you need to return different codes for + different types of errors. + The System.Exit module provides a way to exit the + program and return a specific exit status code to the caller. You can + call exitWith ExitSuccess to return a code + indicating a successful termination (0 on POSIX systems). Or, you can + call something like exitWith (ExitFailure 5), which + will return code 5 to the calling program. + + + + + Dates and Times + + asdf + + + + hunk ./en/ch20-systems.xml 136 - file. Here's an example session with the POSIXPOSIX is - a standard for Unix-like operating systems. Linux, FreeBSD, - Solaris, and MacOS X are all examples of operating systems that - present a POSIX shell and many POSIX-like features. Windows - doesn't, but the Cygwin package can provide many POSIX features for - Windows. + file. Here's an example session with the POSIX }