Perl Tutorials - Herong's Tutorial Examples - v6.01, by Dr. Herong Yang
Built-in Functions to Work with the File System
This section describes Perl built-in functions, chdir(), mkdir(), rmdir(), and unlink() to work with the file system, like to change the current directory, make or remove a directory, or delete a file.
A file system is a tree structure of directories with files associated to directories. Perl offers several built-in functions for you to work with the file system:
1. chdir() - Resets the current directory to a directory identified by the specified path name:
rc = chdir(path_name);
For example, chdir("..") resets the new current directory to the parent directory of the old current directory.
2. mkdir() - Makes a new directory defined by the specified path name:
rc = mkdir(path_name);
For example, mkdir("/temp/test") makes a new directory under /temp in the file system. Notice that "/" works like "\" with ActivePerl on Windows systems.
3. rmdir() - Removes a directory defined by the specified path name, when the directory is empty:
rc = rmdir(path_name);
For example, rmdir("/temp/test") removes the /temp/text directory in the file system. If it is not empty, this function will fail.
4. unlink() - A function to delete a list of files:
rc = unlink(file_list);
For example, unlink("/temp/junk.txt") removes the /temp/junk.txt file in the file system.
Table of Contents
Data Types: Values and Variables
Expressions, Operations and Simple Statements
Name Spaces and Perl Module Files
Hard References - Addresses of Memory Objects
Objects (or References) and Classes (or Packages)
Typeglob and Importing Identifiers from Other Packages
String Built-in Functions and Performance
File Handles and Data Input/Output
Open Directories and Read File Names
►File System Functions and Operations
►Built-in Functions to Work with the File System
stat() - Returns File Statistics
Socket Communication Over the Internet
XML::Simple Module - XML Parser and Generator
SOAP::Lite - SOAP Server-Client Communication Module
Perl Programs as IIS Server CGI Scripts
CGI (Common Gateway Interface)
XML-RPC - Remote Procedure Call with XML and HTTP
RPC::XML - Perl Implementation of XML-RPC
Integrating Perl with Apache Web Server
CGI.pm Module for Building Web Pages
LWP::UserAgent and Web Site Testing
Converting Perl Script to Executable Binary