forro has asked for the wisdom of the Perl Monks concerning the following question:
Hello Monks!
Task: I have a .txt file with filenames which have to be deleted. I need to read the file, append the ".png" and ".txt" extension to the filenames. Then, I need to search for those files on my system, print out the full paths and in the end, to delete the files. This is what I got until now:
#!/usr/bin/perl use strict; use warnings; use File::Find; print "Files to be deleted: \n"; open ("file", "remove.txt") || die ("Could not open file. \n $!"); @text=<file>; print(@text); close("file"); my $dir = "/Downloads/png_files/"; find(\&wanted, $dir); sub wanted { print $File::Find::name if -d };
Problem: I tried, but failed, in appending the extensions to the filenames in my .txt file and I also do not know how to pass the values stored in the array to the find () subroutine, the "if" clause.
I just started learning Perl and it's a bit out of my reach. If anyone can lend a helping hand, I would appreciate it.
Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Read .txt file -> append extension -> find on disc -> delete
by Perlbotics (Archbishop) on Oct 27, 2012 at 12:35 UTC | |
|
Re: Read .txt file -> append extension -> find on disc -> delete
by Anonymous Monk on Oct 27, 2012 at 10:15 UTC | |
|
Re: Read .txt file -> append extension -> find on disc -> delete
by Anonymous Monk on Oct 27, 2012 at 10:25 UTC |