Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File search problem

Status
Not open for further replies.

kirk124

Programmer
Apr 15, 2003
26
US
Hi,
I am recursively searching my pc for a some files and renaming them. I can't get my script to avoid searching in a particular folder and its subdirectory. The folder in particular is 'c:\\WINNT'.

Here a snippet:

finddepth (\&rename_file_dir , "c:\\" );

sub rename_file_dir
{
if( /(.*)csscs_ref(.*)/i )# any files or directories
{
$orig = $File::Find::name ;
$concat = $File::Find::dir . "\/$1$new_hostname$2";
rename($orig, $concat) || print "error can't rename $orig to $concat: $!"
}
}


How can I rewrite the subroutine so that the script looks for all file that has the substring "csscs_ref" but not in the 'c:\\WINNT' folder.

--thanks
 
Try something like this:
Code:
if( /(.*)csscs_ref(.*)/i && $File::Fine::dir !~ /^c:\\WINNT/i)
Perform a negative search on the directory to see if it contains an invalid path. Syntax/formatting might be off with this example, but you get the idea.

----------------------------------------------------------------------------------
...but I'm just a C man trying to see the light
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top