Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 29th, 2010, 09:04 AM
Authorized User
 
Join Date: Feb 2007
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"
--------------------------------------------------------------------------------------------
 
Old November 30th, 2010, 01:50 AM
Authorized User
 
Join Date: Aug 2009
Posts: 23
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Does file names in zsk_bestanden_4.txt contain quotes?
 
Old November 30th, 2010, 05:30 AM
Authorized User
 
Join Date: Feb 2007
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
 
Old November 30th, 2010, 08:38 AM
Authorized User
 
Join Date: Aug 2009
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";
  }
}
 
Old December 1st, 2010, 08:51 AM
Authorized User
 
Join Date: Feb 2007
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
 
Old December 1st, 2010, 08:57 AM
Authorized User
 
Join Date: Aug 2009
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.
 
Old December 2nd, 2010, 10:56 AM
Authorized User
 
Join Date: Feb 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have tried and it works!

Thanks very much!

John





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.