Home: Perl Programming Help: Win32 Programming Help:


Dec 4, 2001, 3:33 PM

Views: 8796

I was curious how i would go about deleting files on my comp through perl. (i have Windows 98). I tried this:

#!/usr/bin/perl -w 
print `del C:/path/to/file.txt`;
print "Deleted file.txt";

But for some reason that does not work... but when i type that into the command prompt it does. Where exactly does the ` send this command too? It always tells me file not found. Also i tried to use system(); but i am not totally sure how you use that correctly either. Last question, how can i run a program from the command prompt.

Thanks for the help :)

@letters = ('A'..'Z', 'a'..'z', '1'..'5', '_');
@i = ( '15', '43', '40');
print @letters [ @i, -1, 55];


Dec 4, 2001, 5:48 PM

Views: 8795
Re: Deleting...

Most likely, the problem you're seeing is the Windows being confused by your use of slashes, as it normally expects to see \'s instead of /'s when referring to a file.

A better solution than using backticks and del, however, is Perl's own unlink() function (used as my $deleted = unlink(@files);, where $deleted is the number of files actually deleted).


Feb 11, 2002, 2:55 AM

Views: 8788
Re: [Pro_4] Deleting...

Another reason might be the long file names.

Put the whole path into double quotes in case the path contains space characters.

And anyway, unlink() is portable and it is generally preferable to use internal functions Smile

Jean Spector
SQA Engineer @ Exanet

There are only 10 types of people in the world -
Those who understand binary, and those who don't.