################################################################################ # File: dir_list.pl # # <> # # Purpose: Lists the contents of the current directory. # # Created: 20th October 2000 # Updated: 3rd January 2001 # Author: Synesis Software (Pty) Ltd (C) 2000. All rights reserved. # (www.synesis-group.com/software). # # Status: Public-domain # # Copyright: Synesis Software (Pty) Ltd provides the source code contained in # this file/document free-of-charge according to the following # conditions: # # (i) No warranty, expressed or implied, is given as to the # correctness or efficiency of the code. # (ii) No part of this code may be modified or copied, by whatever # means without including a copy of this notice in its entirety # (this means the all content between the <> and <<:END>> # tokens inclusive, including, and not limited to, purpose, date # of creation, date of last update, authorship, address, copyright # and status). # (iii) This code, in whole or part, remains the property of # Synesis Software (Pty) Ltd, whether incorporated as-is, or in # modified form. # # <<:END>> # # ############################################################################## #_SYNSOFT_VER_PL_DIR_LIST_MAJOR 1 #_SYNSOFT_VER_PL_DIR_LIST_MINOR 0 #_SYNSOFT_VER_PL_DIR_LIST_REVISION 2 #_SYNSOFT_VER_PL_DIR_LIST_EDIT 3 use Cwd; $sep = "\\"; $sep_re = $sep . $sep; sub trim_line { $_ = @_[0]; s/[\r\n]+$//; # strip cr-lf from end of line s/^\s*(.*?)\s*$/$1/; # trim spaces return $_; } $argc = scalar(@ARGV); if($argc > 0) { $searchdir = $ARGV[0]; $print_search_dir = 1; } else { print "Enter the directory, or to use current:"; $searchdir = ; } $searchdir = trim_line($searchdir); $print_search_dir = 0; if(!$searchdir) { $searchdir = cwd(); $print_search_dir = 1; } if($print_search_dir) { print qq(Searching directory "$searchdir"\n); } opendir SEARCHDIR, $searchdir; # Need to strip the trailing separator, since the filters below concatenate the # search path and the filename if($searchdir =~ /.*?$sep_re$/) { $searchdir =~ s/(.*?)$sep_re$/$1/; } @all = readdir SEARCHDIR; @alldirs = grep -d, map "$searchdir$sep$_", grep !(/^\.\.?$/), @all; @allfiles = grep -f, map "$searchdir$sep$_", @all; print Directories . "\n"; foreach $dir (@alldirs) { print "Directory: " . $dir . "\n"; } print Files . "\n"; foreach $file (@allfiles) { print "File: " . $file . "\n"; }