Connecting Tech Pros Worldwide Forums | Help | Site Map

Directory recursing only for C files and print all the directories which have them

Newbie
 
Join Date: Aug 2006
Posts: 3
#1: Aug 18 '06
Hello,

I am a li'l new to perl scripting and I am trying to write a script which can give me the result in a particular format. I need to generate all the directories as well as the subdirectories that contain only c files in them in an order say starting with one directory follwed by its sub directories etc. Hope this is clear!

Can somebody help me with the Perl script??

Thanks,
sreemakam

Newbie
 
Join Date: Aug 2006
Posts: 7
#2: Sep 11 '06

re: Directory recursing only for C files and print all the directories which have them


#you only needed to say this line:
>I need to generate all the directories as well as the subdirectories that contain only c files in them.

# do you want it from the entire hard drive or just from a specific folder?
Member
 
Join Date: Sep 2006
Posts: 61
#3: Sep 11 '06

re: Directory recursing only for C files and print all the directories which have them


use the following code in ur program...

system("find / -name *.c > a.out");

Read line by line from the file a.out and cut the basename and you will get the directory containing that .c file.
Newbie
 
Join Date: Aug 2006
Posts: 3
#4: Sep 11 '06

re: Directory recursing only for C files and print all the directories which have them


Hi,
Thanks for the replies. I could get what i was looking for! Actually, its not just recursing through the directories to get the C files. But, i need to generate the paths of the folders and sub-folders that contain the c file which is taken as the input to another program.

To get the required C files, all i did was...

use File::Find::name;
find(\&func_name, $path);

sub func_name
{
my $file = File::Find::name;
if ($file =~ /\.c/)
{ print $file;
}
}

For the paths, i am writing this into a file and then, generating the paths so that they are not repeated more than once.
Reply