in reply to Perl script to delete files using regex
If, as it appears, you are trying to find a file with a fixed name rather than a group of files with a common part to their name, no regexp is required. Just perform a string comparison on the filename.
if ($file eq 'carlos.txt')
This script will list everything in the directory where the script is located and point out the file named 'carlos.txt'
use strict; my $file; # Read the current directory into an array opendir(my $dir, '.'); my @files = readdir($dir); closedir ($dir); # Iterate over array to file file foreach $file(@files) { print "$file"; if ($file eq 'carlos.txt') { print " <------------- Found File"; } print "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl script to delete files using regex
by GrandFather (Saint) on Nov 24, 2020 at 00:52 UTC | |
by Bod (Parson) on Nov 24, 2020 at 01:01 UTC | |
by GrandFather (Saint) on Nov 24, 2020 at 01:30 UTC |