in reply to Re: \n in filenames
in thread \n in filenames

Thank you Zaxo. It worked. With the added bonus that the script deleted itself, of course (not the kind of script you want to leave lying around!)

I don't really understand why it worked or why

unlink "*\n"
or just unlink "*"didn't work. I read the glob section in the Camel book and I'm not much wiser.

Replies are listed 'Best First'.
Re: Re: Re: \n in filenames
by Fletch (Bishop) on Oct 21, 2001 at 05:05 UTC

    This is because unlink is calling the underlying system call unlink which doesn't grok globs. You could do something like this:

    opendir( CUR, "whateverdir" ) or die "opendir: $!\n"; do { unlink or warn "unlink " . quotemeta($_) . ": $!\n"} for grep /\n$/, readdir( CUR ); closedir( CUR );

    And just for reference, a non-perl solution would be to use something like this (which uses a find-ism (-print0) which may not work everywhere).

    $ find -name "*\n" -print0 | xargs -0 rm