#!/usr/bin/perl #FindDir #Usage example - perl finddir P12345678 #Usage example - perl finddir D12345678 package finddir; our $package = 'FindDir'; use strict; use warnings; use File::Find qw(find); #*****************Path Variables************************ our @RDDSpaths = ('C://Temp/hddzip/', ); our @NASpaths = ('C://Temp/Alcohol/', ); #******************************************************* #Die if no parameters are given to the program @ARGV or die "$package: no parameters given\n"; #Checking for valid dir name our $DIR=shift; chomp $DIR; $DIR =~qr{^[LIDMP]\d{8}$} or die "$package: $DIR is not a valid Media Identifier\n"; #Set variables our $found = 0; our $location = 0; #If DIR starts with either I,D or M and has another 8 characters process if ($DIR =~qr{^[IDM]\d{8}$}) { print "Searching for $DIR on NAS\n"; #Search NAS paths find(\&wantedNAS, @NASpaths); $found or print "Unable to locate $DIR in path"; if ($found != 0) { print "Found $DIR in $location\n"; } sub wantedNAS { return unless -d; $File::Find::prune = 1 if /[IDM]\d{8}$/; # Don't recurse. print "$File::Find::dir/$_/\n" if /[IDM]\d{8}$/; if ($_ eq $DIR){ #Store path location of DIR if found $location = $File::Find::name; $found++; #exit; } } } #Else If DIR starts with either L or P and has another 8 characters process else { print "Searching for $DIR on RDDS\n"; find(\&wantedRDDS, @RDDSpaths); $found or print "Unable to locate $DIR in path"; if ($found != 0) { print "Found $DIR in $location\n"; } sub wantedRDDS { return unless -d; $File::Find::prune = 1 if /[LP]\d{8}$/; # Don't recurse. print "$File::Find::dir/$_/\n" if /[LP]\d{8}$/; if ($_ eq $DIR){ #Store path location of DIR if found $location = $File::Find::name; $found++; #exit; } } }