Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


Java/Open Source Daily

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


File Tests

File Tests

  • Finally, Perl provides many methods for determining information about files on the file system using "File tests". For the purposes of this tutorial, there are too many types of file tests to cover them all in depth. Further, they are covered extensively elsewhere. However, the most frequent syntax of file tests used in CGI applications follows the form:

    if ([filetest] [filename] && [other filetest] [filename])
           {
           do something
           }
    

  • Consider the following example that checks to see if a file exists (-e) and is writable (-w) by us, and if so deletes it:

    if ((-e "temp.file") && (-w "temp.file"))
           {
           unlink ("temp.file");
           }
    

  • The following lists several common file tests.

Test Description
-r File or directory is readable
-w File or directory is writable
-x File or directory is executable
-o File or directory is owned by user
-e File or directory exists
-z File exists and has zero size
-s File or directory exists and has non-zero size
-f Entry is a plain file
-d Entry is a directory
-T File is text
-B File is binary
-M Modification age in days
-A Access age in days

Additional Resources:

Deleting, Renaming and Changing the Permissions of Files
Table of Contents
Getting Information About a File With stat


Up to => Home / Authoring / Scripting / Tutorial