Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 29th, 2010, 09:04 AM
Authorized User
Points: 94, Level: 1
Points: 94, Level: 1 Points: 94, Level: 1 Points: 94, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delete files without

Hello,

I am trying to delete files using Perl. The names of the files are in a text file called 'zsk_bestanden_4.txt'. The following program runs without problem but only produces the message that 'File could not be removed'. Indeed there are no files deleted.
What goes wrong?
Any help would be very much appreciated,

John

---------------------------------------------------------------------------------------------------------------------------------
use strict;
use warnings;
open (h_zsk_bestanden_4, "J:\\m_20_zsk\\m_02_bestanden\\zsk_bestanden_4.txt ") or die ("Unable to open zsk_bestanden_4.txt");
while (my $naam_meerling = <h_zsk_bestanden_4>)
{
chomp $naam_meerling;
my $bestand_1 = $naam_meerling;
unlink $bestand_1 or print "File could not be removed\n\n";
}
---------------------------------------------------------------------------------------------------------------------------------

zsk_bestanden contains:
--------------------------------------------------------------------------------------------
"J:\\m_23_zsk_bewaar_test\\test_000009_091243. xml"
"J:\\m_23_zsk_bewaar_test\\test_000010_091244. xml"
"J:\\m_23_zsk_bewaar_test\\test_000011_091245. xml"
"J:\\m_23_zsk_bewaar_test\\test_000012_091247. xml"
"J:\\m_23_zsk_bewaar_test\\test_000013_091249. xml"
"J:\\m_23_zsk_bewaar_test\\test_000014_091250. xml"
"J:\\m_23_zsk_bewaar_test\\test_000015_091251. xml"
"J:\\m_23_zsk_bewaar_test\\test_000029_091285. xml"
--------------------------------------------------------------------------------------------
Reply With Quote
  #2 (permalink)  
Old November 30th, 2010, 01:50 AM
Authorized User
Points: 93, Level: 1
Points: 93, Level: 1 Points: 93, Level: 1 Points: 93, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2009
Location: Moldova
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Does file names in zsk_bestanden_4.txt contain quotes?
Reply With Quote
  #3 (permalink)  
Old November 30th, 2010, 05:30 AM
Authorized User
Points: 94, Level: 1
Points: 94, Level: 1 Points: 94, Level: 1 Points: 94, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Yes, the quotes are in the file.

Hi Chorny,

Yes, the quotes are in the file, but they can be omitted when this file is composed

John
Reply With Quote
  #4 (permalink)  
Old November 30th, 2010, 08:38 AM
Authorized User
Points: 93, Level: 1
Points: 93, Level: 1 Points: 93, Level: 1 Points: 93, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2009
Location: Moldova
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Try this program:

Code:
use strict;
use warnings;
open (my $h_zsk_bestanden_4, '<', "J:\\m_20_zsk\\m_02_bestanden\\zsk_bestanden_4.txt ") or die ("Unable to open zsk_bestanden_4.txt");
while (my $naam_meerling = <$h_zsk_bestanden_4>)
{
  chomp $naam_meerling;
  my $bestand_1 = $naam_meerling;
  if (-e $bestand_1) {
    unlink $bestand_1 or print "File could not be removed\n\n";
  } else {
    warn "$bestand_1 does not exist";
  }
}
Reply With Quote
  #5 (permalink)  
Old December 1st, 2010, 08:51 AM
Authorized User
Points: 94, Level: 1
Points: 94, Level: 1 Points: 94, Level: 1 Points: 94, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unfortunately I get a warning

Thanks for your program, unfortunately I get the fiollowing warning

"J:\\m_23_zsk_bewaar_test\\test_000009_091243. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000010_091244. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000011_091245. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000012_091247. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000013_091249. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000014_091250. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000015_091251. xml" does not exist
"J:\\m_23_zsk_bewaar_test\\test_000029_091285. xml" does not exist

(I have addes ''\n\n' to the 'warn "$bestand_1 does not exist"; line.

Regards,

John
Reply With Quote
  #6 (permalink)  
Old December 1st, 2010, 08:57 AM
Authorized User
Points: 93, Level: 1
Points: 93, Level: 1 Points: 93, Level: 1 Points: 93, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2009
Location: Moldova
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I suppose file names really does not have quotes. You should generate files without them or remove then in this program.
Reply With Quote
  #7 (permalink)  
Old December 2nd, 2010, 10:56 AM
Authorized User
Points: 94, Level: 1
Points: 94, Level: 1 Points: 94, Level: 1 Points: 94, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried and it works!

Thanks very much!

John
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How Can I Delete Cookie files. MICZ VB How-To 4 August 18th, 2007 04:56 AM
delete files in the server miguel.ossa Classic ASP Basics 1 September 5th, 2005 12:15 PM
Delete Files qazi_nomi Classic ASP Basics 7 October 18th, 2004 06:55 PM
Delete files on closing browser spacy ASP.NET 1.x and 2.0 Application Design 7 September 8th, 2004 04:24 PM
How Can I Delete Cookie files. MICZ Pro VB 6 2 August 13th, 2004 10:44 AM



All times are GMT -4. The time now is 11:23 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.