By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,695 Members | 1,956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,695 IT Pros & Developers. It's quick & easy.

Problem faced while deleting the required files from directory !!!

P: 65
Hi Everyone,

i have written small code where it fetches the required files from required dir path
& deleting those files before proceeding further.

script goes like this:
Expand|Select|Wrap|Line Numbers
  1. my $@file_names;
  2. my $full_path;
  3. my $dir  = "c:\\svap\\input\\";
  4. my $file_name ="*.xls";
  5. &check_file($dir,$file_name);
  6.  
  7. sub check_file($dir,$file_name){
  8. $full_path = $dir.$file_name;
  9. @file_names = glob($full_path);
  10.                   if(@file_names eq 0){
  11.                     print " no *.xls file found,can proceed further!!!";
  12.                    }
  13.                  else{
  14.                       foreach my $i(@file_names){
  15.                            unlink "$i";
  16.                               }
  17.                         }
  18.                 }
  19.  
The above code works fine if there is only *.xls file but my problem is:
sometimes i get *.xls + filename.xls.xls files in the dir

how to delete these *.xls.xls files with out altering the $file_name value(ie,$file_name = "*.xls.xls")

Can anyone help me on this ???

Regards,
Vijayal
Sep 20 '08 #1
Share this Question
Share on Google+
4 Replies


KevinADC
Expert 2.5K+
P: 4,059
The code you posted will not even run, so post some good code. There is little sense in helping you with code that is bad to begin with.

Bareword found where operator expected at script line 2, near "$@file_names"
(Missing operator before file_names?)
Illegal character in prototype for main::check_file : $dir,$file_name at script line 8 .
Bareword found where operator expected at script line 2, near "$@file_names"
(Missing operator before file_names?)
Illegal character in prototype for main::check_file : $dir,$file_name at script line 8 .
Can't use global $@ in "my" at script line 2, near "my $@"
syntax error at script line 2, near "$@file_names"
Sep 20 '08 #2

P: 65
Hi Kevin,

As i am newbiee to perl, it was my mistake(type error)

2nd line has to be:
Expand|Select|Wrap|Line Numbers
  1. my @file_names;
  2.  
and then in line no 8, am just trying to concatenate the 2 values to get this value
Expand|Select|Wrap|Line Numbers
  1. c:\svap\input\*.xls
  2.  
please can you help me to delete *.xls.xls file ??

Thanks,
Vijayarl
Sep 20 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
There are other problems with your code. See how this works:

Expand|Select|Wrap|Line Numbers
  1. my $dir  = 'c:\svap\input\\';
  2. my $file_name = '*.xls';
  3. &check_file($dir,$file_name);
  4.  
  5. sub check_file {
  6.    my ($dir, $path) = @_;
  7.    my @file_names = glob("$dir$path");
  8.    if(@file_names == 0){
  9.       print " no *.xls file found,can proceed further!!!";
  10.    }
  11.    else{
  12.       foreach my $i (@file_names){
  13.          unlink "$i" or print "Can't delete $i : $!\n";
  14.       }
  15.    }
  16. }
Sep 21 '08 #4

P: 65
hi Kevin,

Thank you very much for your support... it really worked ..
able to rectify my mistakes from you..
thanks once again...
pls keep doing good work, it helps all newbiee's in perl.

bye
vijayarl
Sep 21 '08 #5

Post your reply

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