in reply to How to compare User Input to a file Name
As stated earlier I really appreciate the advice give so far. Now for the followup question. I am using this script to clean out directories.
For this example I have 4 files in the /User/jsmith/data directory named test1-4. I want to delete all four of them so far I have the following:
Now my questions is: Is there a more effective way to use the rmtree to delete multiple directories other than using a while loop, like I did in my above code?#!/usr/bin/perl -w use strict; use File::Glob qw(bsd_glob); use File::Path; my $fname = "empty"; my @found_files; my @found_files1; while (! @found_files) { print "Please enter the file name: "; chomp($fname = <STDIN>); @found_files = glob( "/Users/jsmith/data/$fname*" ); if (@found_files != 1) { print "File does not exist!"; }; }; print "The following files have been deleted: \n"; print "$_\n" for @found_files; while (@found_files != 0) { rmtree (@found_files); @found_files = glob( "/Users/jsmith/data/$fname*"); };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to compare User Input to a file Name
by toolic (Bishop) on Sep 24, 2008 at 00:46 UTC |