toolsandutils/productionbldtools/BFrC/listdir.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 #!/usr/bin/perl
       
     2 
       
     3 # Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 # All rights reserved.
       
     5 # This component and the accompanying materials are made available
       
     6 # under the terms of "Eclipse Public License v1.0"
       
     7 # which accompanies this distribution, and is available
       
     8 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 #
       
    10 # Initial Contributors:
       
    11 # Nokia Corporation - initial contribution.
       
    12 #
       
    13 # Contributors:
       
    14 #
       
    15 # Description:
       
    16 # listdir.pl - displays the contents of a directory and all its subdirectories
       
    17 # 
       
    18 #
       
    19 
       
    20 my ($path, $files) = readOpts(@ARGV);
       
    21 
       
    22 list($path, $files);
       
    23 
       
    24 exit 0;
       
    25 
       
    26 sub readOpts(@)
       
    27 	{
       
    28 	my (@args) = @_;
       
    29 
       
    30 	my $path = undef;
       
    31 	my $files = 0;
       
    32 
       
    33 	foreach my $arg (@args)
       
    34 		{
       
    35 		if ($arg =~ /^-/)
       
    36 			{
       
    37 			if ((lc($arg) eq "--help")
       
    38 			  ||(lc($arg) eq "-h")
       
    39 			   )
       
    40 			   	{
       
    41 				showHelp();
       
    42 				exit 0;
       
    43 				}
       
    44 			if ((lc($arg) eq "--files")
       
    45 			  ||(lc($arg) eq "-f")
       
    46 			  )
       
    47 			  	{
       
    48 				$files = 1;
       
    49 				}
       
    50 			else
       
    51 				{
       
    52 				print STDERR "Option '$arg' not recognised.\n\n";
       
    53 				print STDERR "Try 'listdir.pl --help' for help.\n";
       
    54 				exit 1;
       
    55 				}
       
    56 			}
       
    57 		else
       
    58 			{
       
    59 			if (defined($path))
       
    60 				{
       
    61 				print STDERR "Listdir accepts only one argument.\n\n";
       
    62 				print STDERR "Try 'listdir.pl --help' for help.\n";
       
    63 				exit 1;
       
    64 				}
       
    65 			else
       
    66 				{
       
    67 				$path = $arg;
       
    68 				}
       
    69 			}
       
    70 		}
       
    71 	
       
    72 	if (!defined($path))
       
    73 		{
       
    74 		print STDERR "Listdir must be given a path to list.\n\n";
       
    75 		print STDERR "Try 'listdir.pl --help' for help.\n";
       
    76 		exit 1;
       
    77 		}
       
    78 	
       
    79 	return ($path, $files);
       
    80 	}
       
    81 
       
    82 sub list($)
       
    83 	{
       
    84 	my ($path, $files) = @_;
       
    85 	
       
    86 	opendir(PATH, $path);
       
    87 	my @dir = readdir(PATH);
       
    88 	closedir(PATH);
       
    89 
       
    90 	foreach $entry (@dir)
       
    91 		{
       
    92 		if ($entry =~ /^\.\.?$/)
       
    93 			{
       
    94 			}
       
    95 		elsif (-d $path."\\".$entry)
       
    96 			{
       
    97 			if (!$files)
       
    98 				{
       
    99 				print $path."\\".$entry."\\\n";
       
   100 				}
       
   101 			list($path."\\".$entry, $files);
       
   102 			}
       
   103 		else
       
   104 			{
       
   105 			print $path."\\".$entry."\n";
       
   106 			}
       
   107 		}
       
   108 	}
       
   109 
       
   110 sub showHelp()
       
   111 	{
       
   112 	my ($date) = @_;
       
   113 	
       
   114 	print "listdir.pl [options] Path\n";
       
   115 	print " - displays the contents of a directory and all its subdirectories\n\n";
       
   116 	print "   As dir /S /B, except only the path below the current dir is given\n\n";
       
   117 	print "  Path - The path to the root of the files to be modified\n";
       
   118 	print "Options:\n";
       
   119 	print "  --files or -f - Only list the files in each subdir, not the dirs themselves\n";
       
   120 	print "  --help or -h - Display this message\n\n";
       
   121 	}
       
   122