in reply to Unlinking...
With Perl, you don't open a directory like you would a normal file. Use the opendir command instead. Also, at least on my Unixy machine, that will attempt to read a file in the root directory -- no guarantee what it will do on Windows.
Obviously, if the directory open fails, reading from the filehandle won't work. So the while line doesn't do anything -- which is good, considering what happens next.
The unlink line will probably do the trick (depending on how well globbing is implemented in your version of Perl). Unfortunately, it returns a list of all of the files ending in '.txt' in the current directory, which is hardly what you want. You'll either need to chdir to the directory you want to work on, or prepend that directory name to each of the files you want to remove.
Add the requisite error checking, too. I'd code it with readdir and grep as someone already posted.
|
|---|