Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I am new to Perl scripting. I need some ideas regarding a requirement.
That is I need to read file names and their size from folders and sub folders and if the size of the file is "0/ZERO" print out an error message saying "file size is zero with their file names".
Except I constantly have three files which are always zero so it should avoid these files and check the rest of them.
Hi,
I am new to Perl scripting. I need some ideas regarding a requirement.
That is I need to read file names and their size from folders and sub folders and if the size of the file is "0/ZERO" print out an error message saying "file size is zero with their file names".
Except I constantly have three files which are always zero so it should avoid these files and check the rest of them.
Thanks
This sounds very much like homework.
And we'll be glad to HELP you with this...but we're not going to write it for you. Post what you've written, and where you're getting stuck. Otherwise, there are many Perl tutorials you can find via Google, that can tell you how to check file sizes.
Hi,
Sure I am posting the script I am working on right now . I am reading the file names recursively. Next step would be to get the file size and if it is zero print an error message. I think we can use file size = -s "file" but not sure how to use it correctly and also I need to avoid three files from my directory reading because their size is by default zero.
#!/usr/local/bin/perl
use File::Find ;
$search = shift || 'p::\ documents\new folder' ;
# Get an array of all subdirectories
find sub { push @dirs, $File::Find::name if -d }, $search ;
for $dir ( @dirs ) {
opendir $dh, $dir or do { warn "Cannot open '$dir' $!" ; next ; } ;
opendir( DIR, "$dir" ) ;
@files = grep( /\/, readdir( DIR ) ) ;
closedir( DIR ) ;
Hi,
The above code is a patch work from here and there as I am new to Perl but need to complete a task immediately. I tired the code above by declaring $file after s because it is the variable which is holding my file names but no luck the size is not being retrieved.
Hi,
The above code is a patch work from here and there as I am new to Perl but need to complete a task immediately. I tired the code above by declaring $file after s because it is the variable which is holding my file names but no luck the size is not being retrieved.
Thanks,
So how about posting the code that's not working, and what it's returning? Or do you expect us to fully test and debug YOUR program for you???
Hi,
Sorry I did not mean that way. What I said was the script to traverse is working, in that script I added the code which was posted by "druuna" by making changes accordingly and it did not work. So I requested for help thinking I am not using the code exactly.
Please post your thread in only one forum. Posting a single thread
in the most relevant forum will make it easier for members to help
you and will keep the discussion in one place. This thread is being
closed because it is a duplicate.
It would be much more acceptable (and honest) if you didn't use
two user accounts, either. I respectfully ask that you cease
using two accounts to saturate the forums with duplicate threads,
whatever the motivation behind it is.
Hi,
Below is the script till now. To get the file size I declared -s and declaring my variable after that which holds my location and file names at the print statement, but no output is being generated. Next thing is I have three basic files which will always be zero so it has to check the rest of the files leaving this three for file size.
#!/usr/local/bin/perl
use File::Find ;
# Get the directory from the command line
# or use the default directory
$search = shift || 'p:\Documents and Settings\user\Desktop\' ;
find sub { push @dirs, $File::Find::name if -d }, $search ;
for $dir ( @dirs ) {
opendir $dh, $dir or do { warn "Cannot open '$dir' $!" ; next ; } ;
opendir( DIR, "$dir" ) ;
@files = grep( /\./, readdir( DIR ) ) ;
closedir( DIR ) ;
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.