I need to write the code for a script to count and display # of files and directories and then dispaly the # of each as well as the script name as output. I also have to sow a command to execut the script which I know already
hotlantas69
0
Newbie Poster
Recommended Answers
Jump to PostHi,
Did you have any sample code to start with? What shell are you writing for? I sense that this is a homework problem... and while we like to help, we also encourage growth and self-learning.
Christian
Jump to PostThe following script shows show I would do it, this is with a script instead of the commandline, of course in reality I would use perl but this is a basic idea on how to use bash to do it.
#!/bin/bash directory=0 file=0 total=0 for a in …
Jump to PostYou are right that would be a simpler method of doing it, but since it sounded a lot like a homework assignment I was hoping to just give an indication of how it could be done, whilst indicating that there was better ways to do it, rather than giving the …
Jump to PostLudootje - It can be done in perl very easily, and since primarily I am a perl programmer that would be my tool of choice.
opendir(TMP, "/adirectory"); while ($f=readdir(TMP)) { if (-d $f) { $directory++; } else { $file++; } $total++; } closedir(TMP);
Obviously just counting files …
Jump to PostI guess I should give Perl/Python another try...
Now if only it didn't take so long before being able to write something actually *useful*, I wouldn't give up so easily :)I don't know about Perl, I'm assuming it'd be the same way, but with Python, it's SUPER easy, fun, …
All 18 Replies
kc0arf
68
Posting Virtuoso
Team Colleague
hotlantas69
0
Newbie Poster
liliafan
53
Junior Poster
Ludootje
0
Newbie Poster
liliafan
53
Junior Poster
Ludootje
0
Newbie Poster
liliafan
53
Junior Poster
Ludootje
0
Newbie Poster
alc6379
120
Cookie... That's it
Team Colleague
Ludootje
0
Newbie Poster
liliafan
53
Junior Poster
Ludootje
0
Newbie Poster
alc6379
120
Cookie... That's it
Team Colleague
liliafan
53
Junior Poster
Ludootje
0
Newbie Poster
liliafan
53
Junior Poster
Ludootje
0
Newbie Poster
liliafan
53
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.