467,146 Members | 1,010 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

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

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

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
  • viewed: 1512
Share:
4 Replies
KevinADC
Expert 2GB
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
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 2GB
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
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.

Similar topics

1 post views Thread by Alfons | last post: by
7 posts views Thread by Amar | last post: by
6 posts views Thread by Justin Time | last post: by
3 posts views Thread by Pitcairnia | last post: by
1 post views Thread by Lee | last post: by
1 post views Thread by vijju | last post: by
4 posts views Thread by James Wong | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.