473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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
4 1679
KevinADC
4,059 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
4,059 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

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

Similar topics

1
by: Alfons | last post by:
Hello, I have build a program that can do file transferring between a Windows XP computer and a DOS computer via a serial port. The Windows program I have build in C++ with Visual Studio 6.0....
7
by: Amar | last post by:
I am trying to connect to my college LDAP directory using ASP.NET. This LDap does not have security as it returns only user demographic information. i do not need to bind with a username or...
6
by: Justin Time | last post by:
Is there any way to to get a list of file names that were deleted as a result of deleting their parent directory?? Cheers
3
by: Pitcairnia | last post by:
The basic purpose of the site is for authenticated users to post event listings, which often include photographs. The user is faced with a page where they can insert all of the information about...
2
by: Wysiwyg | last post by:
I'm going back to a previous asp.net (C#) web project after a few months of inactivity and my first form, the login, won't submit. I ran with the debugger and still can't see how to resolve this. I...
1
by: Lee | last post by:
Hi, when deleting a directory using;- string dir = "whatever"; Directory.Delete(dir); it fails if files/directories exist within the directory being deleted. is there an easy way of...
1
by: vijju | last post by:
Hi all ! I'm an amateur to DB2.I installed DB2 ESE trial edition on my system.It was all going well and suddenly when i was trying to create an instance, i faced a problem which i listed it below....
4
by: James Wong | last post by:
Hi, After I use the function "Directory.Delete" or "Directory.Move", my session will destory. Why? Thanks. James
1
by: john20 | last post by:
Hi All, I am trying to use webpart in my page for that i am putting webpartmanager and webpartzone. but as soon as i am putting webpartmanger in the page it is giving me below error, let me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.