469,322 Members | 1,614 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,322 developers. It's quick & easy.

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

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
Aug 18 '06 #1
3 1895
#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?
Sep 11 '06 #2
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.
Sep 11 '06 #3
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.
Sep 11 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Anand K Rayudu | last post: by
3 posts views Thread by custard_pie | last post: by
19 posts views Thread by SU News Server | last post: by
3 posts views Thread by S. Han | last post: by
5 posts views Thread by KraftDiner | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.