Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Search for file ignore case

by mwah (Hermit)
on May 18, 2008 at 19:32 UTC ( [id://687247]=note: print w/replies, xml ) Need Help??


in reply to Search for file ignore case

In the shell, eg. by using du:

$~>  du -a | egrep -i TEST.MAK

But there are zillions of other ways too.

Regards

mwa

Replies are listed 'Best First'.
Re^2: Search for file ignore case
by ikegami (Patriarch) on May 18, 2008 at 19:49 UTC
    du -a can be replaced by find. That'll eliminate the leading junk.
Re^2: Search for file ignore case
by Noame (Beadle) on May 18, 2008 at 20:04 UTC

    i need perl command to find the file under unix account. I've get the file from function, e.g: TeST.maK.

    Once i've the file name i need to look for the correct name under spacifiad directory using ignore case.

    if the corret file is: TEST.mak i need to initalize variable with it.

      The following code shows a function that will receive the directory where to look for the files and the filename you got from function (TeST.maK). It will then read the directory contents and perform a test to see if the filename matches any of the files in the directory. The i modifier on the regexp makes that match case insensitive. If a match is found, the actual name of the file is returned, otherwise the returned value will be an empty string.

      sub getFileName { my $dir = shift; my $file = shift; opendir(DIR, $dir); my @dirContent = readdir(DIR); closedir(DIR); foreach my $content (@dirContent) { if($file =~ /^$content$/i) { # filename matches return $content; } } return ''; }

      note: verbose solution for clarity.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://687247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-20 05:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found