p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Perl (http://p2p.wrox.com/forumdisplay.php?f=196)
-   -   Delete files without (http://p2p.wrox.com/showthread.php?t=81737)

John2112 November 29th, 2010 09:04 AM

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"
--------------------------------------------------------------------------------------------

chorny November 30th, 2010 01:50 AM

Does file names in zsk_bestanden_4.txt contain quotes?

John2112 November 30th, 2010 05:30 AM

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

chorny November 30th, 2010 08:38 AM

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";
  }
}


John2112 December 1st, 2010 08:51 AM

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

chorny December 1st, 2010 08:57 AM

I suppose file names really does not have quotes. You should generate files without them or remove then in this program.

John2112 December 2nd, 2010 10:56 AM

I have tried and it works!

Thanks very much!

John


All times are GMT -4. The time now is 02:01 AM.

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