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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Win32 Programming Help:
Deleting...

 



Pro_4
User

Dec 4, 2001, 3:33 PM

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

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

Code
#!/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];


Kanji
User

Dec 4, 2001, 5:48 PM

Post #2 of 3 (4236 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).




Jean
User


Feb 11, 2002, 2:55 AM

Post #3 of 3 (4229 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
jean.spector@softhome.net


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