Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Delete specific file in directory.

Posted by TedH (TedH), 14 February 2005
I've got a blog script that can create files etc. but has no delete function. So I want to put together a little script to do that.

I can list the files fine. I know I can delete one file with unlink by typing in the name. See below:

---------
Files:
one.txt
two.txt
three.txt
---------
Code:
#!perl

use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
print "Content-type: text/html\n\n";

@files = glob "*.txt";

foreach $file (@files) {
 print "<a href='file'>$file</a><br>\n";
}

unlink "one.txt";
---------
this leaves two.txt and three.txt files and deletes one.txt okay.
---------

How do I make the link delete the particular file?

I've spent two days searching all over the place and there seems to be a concerted effort by some programmers and tutors to see how many zillions of files they can delete at once (it's almost laughable), but not just one file.


Hope you can help, thanks - Ted

Posted by admin (Graham Ellis), 15 February 2005
You'll need to set up the link as it it was a form.

e.g.  <a href=/cgi-bin/demo.pl?file=abc.txt>abc.txt</a>

Then in the code

($fntd) = ($ENV{QUERY_STRING} =~ /file=(.*)/);
unlink $fntd;

I am out of the office and have NOT tested these lines - please read and proceed with care!  You'll also need to add a directory path unless you're trying to delete a file in the cgi-bin directory (which I hope you are NOT!)

Posted by TedH (TedH), 15 February 2005
Thanks Graham.

It is inside the cgi bin, inside a password protected admin script.

I was thinking about the implications, and will probably even password protect the deletion script as well. I've only had one request to have this option and may just leave it off the final version.

At least I know how to do it now so have a basis to work from.

So where are you now? Some warm and sunny again?

Posted by admin (Graham Ellis), 16 February 2005
on 02/15/05 at 22:45:31, TedH wrote:
Thanks Graham.

So where are you now? Some warm and sunny again?


Freezing cold Belgium ... motorway service area on my way back from Munchen to Melksham.   If only places with names that start with the same letter were also PHYSICALLY close to each other ...



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho