------------------------------------------------ On Fri, 25 Jul 2003 15:18:39 -0600, [EMAIL PROTECTED] wrote:
> FYI: I have been doing perl for about two weeks, so if my answer screws you up, > don't sue me please! :D > > You would do something like this: > > foreach my $string (<file>) > { > system "cmd del *string*"; > } > > I believe that is right. But even if I am, some of these other guys will show you a > better way. > While that *might* work you should definitely avoid this approach if at all possible. There are a number of reasons to, a) avoid shelling out if possible (read: last resort), for all of the normal reasons that I suggest people not shell out, insecure, not portable, inefficient, error prone...yada, yada, yada... b) using the "*string*" approach could get ugly (read: insecure, dangerous) real quick. What happens when 'string' is empty because someone left a blank line in the file (ouch).... > -----Original Message----- > From: perlwannabe [mailto:[EMAIL PROTECTED] > Sent: Friday, July 25, 2003 3:04 PM > To: [EMAIL PROTECTED] > Subject: deleting files from the directory from a file list. Please > Help! > > > Here is my problem. I want to delete the files contained in a directory > from a list contained in a file. Here is an example: > > The input file is a regular text file in the following format (call it > myfile.txt); > > item1 > item2 > item3 > item4 > .... > > What I want to do is look in a directory and delete any file in the > directory that contains any item on the list. For example, lets say the > contents of the directory looks like this: > > 07/24/2003 01:27 AM 3,812 heresanitem1 > 07/24/2003 10:42 PM 912,126 heretoitem2 > 07/14/2003 12:19 AM 234 item3ishere > 06/12/2003 10:25 PM 34,049 leavemealone > 06/12/2003 10:25 PM 16,683 leavemealonetoo > 07/22/2003 11:36 PM 1,825 yupitem4yup > .... > > I would like to read each line of the file from "myfile.txt" [getline() I > suppose] and then delete the files that have ANY MATCHING information from > the input file. So if the input file has "item1" it will delete the file > "heresanitem1" as well as "alsoitem1aswell" from the directory. So when I > run the script the sample directory above will look like this: > > 06/12/2003 10:25 PM 34,049 leavemealone > 06/12/2003 10:25 PM 16,683 leavemealonetoo > .... > > This problem has been tough for me. I have read everything I can get my > hands on concerning unlink but I cannot get this problem solved. Any help > appreciated. > > OP, I have not seen the answers given in the newsgroup but possibly a looping use of File::Find combined with an 'unlink'... What have you tried? What has failed? Do you know why? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]