CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Win32 Programming Help:



Dec 4, 2001, 3:33 PM

Post #1 of 3 (8933 views)
Deleting... Can't Post

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

Post #2 of 3 (8932 views)
Re: Deleting... [In reply to] Can't Post

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

Post #3 of 3 (8925 views)
Re: [Pro_4] Deleting... [In reply to] Can't Post

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.


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives