PHP Classes

File: DocumentingDad.php

Recommend this page to a friend!
  Classes of Bob Wedwick   Directory Documentation   DocumentingDad.php   Download  
File: DocumentingDad.php
Role: Example script
Content type: text/plain
Description: Class Source
Class: Directory Documentation
Crawl a directory and document files and changes
Author: By
Last change:
Date: 8 years ago
Size: 6,108 bytes
 

Contents

Class file image Download
#!/usr/bin/php -q
<?php
/*
    Author: Bob Wedwick
    USE: php DocumentingDad.php

    1/27/2016 - a demonstration of how the DocumentADirectory class works.

    A complete description is found in script for the class
    and in the pseudocode design file DocumentADirectory.php.pseudo.

    For this demonstration the file types included are:
         .doc, .php, and .xls,
        and 'noextension', '*test*', 'Samp*' are the file name patterns.

    No file names are excluded.

    This produces and edits a "Read Me" text file with the 'DadWhatsUp.ttt' name.

*/

    # attach the class
    #require_once('DocumentADirectory.php');
   
require_once('/home/bob/bin/DocumentADirectory.php');

   
# create the object
   
$doc = new DocumentADirectory;

   
# do not save backup copies
   
$doc->SavePriorDocumentFlag(false);

   
# set the file types to be documented
   
$doc->IncludeFileExtensions(array('.doc','.xls ','php'));
   
$doc->IncludeNamePatterns(array('noextension', '*test*', 'Samp*'));

   
# document the directory. This runs very quickly.
   
$doc->DocumentDirectory('DadWhatsUp.ttt');

/*

Contents of the example directory (Dad) before running this script for the first time.
    DadSample1.doc
    DadSample3.ph
    DadSample4.php
    DadSample5.phP
    DadTesting.tests
    DadWhatsUp8.text
    DocumentingDad.php
    Hold <- directory
    LogTable2Xml.php.BAK
    noextension
    Populateee.pl
    populate.pl
    popu.sc
    popu.Sh
    Samples <- directory
    SampleXls.xls
    SampleX.ttt
    SampleX.xxx
    test <- directory

*/

/* ========= The first time the above script is run, the file 'DadWhatsUp.ttt' is created with these contents. =======

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Documenting: /home/bob/Dad
* DadWhatsUp.ttt NEW FILE created 20160127-090432
* File Types:
* File Extensions: doc xls php
* Include Name Patterns: 'noextension' '*test*' 'Samp*'
* Case Sensitive
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

DadSample1.doc -- no description.
DadSample4.php -- no description.
DocumentingDad.php -- no description.
noextension -- no description.
SampleXls.xls -- no description.
SampleX.ttt -- no description.
SampleX.xxx -- no description.

========
It shows which directory is being documented, the date and time the document was created, what types of files
are included, and whether or not the file names are case sensitive. The directory named Samples is not listed even
though its name matches a name pattern.

*/

/* ======== The second time the above script is run, the same 'DadWhatsUp.ttt' file is modified. ========

Prior to running the script, a text editor was used to manually make notes and comments to the "Read Me" document.

One file was removed from the directory and another was added to show changes to the "Read Me" document.

-------- Results are below. --------

20160127-103132
 ADDITIONS were made.
 Documented file names are MISSING from the directory.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Documenting: /home/bob/Dad
* DadWhatsUp.ttt NEW FILE created 20160127-090432
* File Types:
* File Extensions: doc xls php
* Include Name Patterns: 'noextension' '*test*' 'Samp*'
* Case Sensitive
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Any descriptive text such as this can be manually added.
Any file names anywhere in the descriptive text are also examined to see if they
match a file extension or name pattern. To include a file name from a different directory in the descriptive text without
it being examined, enclose the name in either single or double quotes. Thus the file "SomewhereElse.php" is not marked as
being missing from the directory.
Directory names, such as the 'Samples' directory, are ignored but may be inserted in the descriptive text.

    The next file names were found because they match one of the file extensions being examined.

DadSample1.doc -- a Word document explaining the universe.
    Found as one of the file extensions to include.

DadSample4.php -- a script that does nothing important.
    Found as one of the file extensions (php) to include.

DocumentingDad.php -- this is the script that operates on this "ReadMe" document named "DadWhatsUp.ttt."
    Found as one of the file extensions (php) to include.

SampleXls.xls -- no description.
    Found as one of the file extensions (xls) to include as well as a name pattern (Samp*).

-------- Note that the location of file descriptions has been re-arranged, which is fine to do -------

    The next file names were found because they match one of the name patterns being examined.

noextension -- just something hanging around with no extension.
    Found as one of the name patterns (noextension) to include.

SampleX.ttt -- no description.
    Found as one of the name patterns (Samp*) to include.

SampleX.xxx -- no description.
    Found as one of the name patterns (Samp*) to include.


---------- Comparing directory contents with names that were ignored, we see that:

These do not match a case sensitive file type nor case sensitive name pattern.
    DadSample3.ph
    DadSample5.phP
    DadTesting.tests
    DadWhatsUp8.text
    LogTable2Xml.php.BAK
    Populateee.pl
    populate.pl
    popu.sc
    popu.Sh

These are are names of subordinate directories. Names that might otherwise look like file names
        are put in single quotes.
    Hold <- directory
    'Samples' <- directory
    'test' <- directory

**ADDITIONS** were made 20160127-103132.
DadSample2.doc -- Oh my goodness! Who put this file here? It belongs somewhere else.

Files **MISSING** from the directory -- 20160127-103132.
SampleX.ttt <-- This was removed from the directory. Once listed as missing, it will not be listed again.

*/


/* ======== The third time the above script is run, the 'DadWhatsUp.ttt' file has the same contents as the
second run but the following was added to the beginning of the document.

20160127-104250
 --NO-- additions were found.
 --NO-- documented file names were found missing from the directory.
...

*/
# end script
?>