View Full Version : Need a script that will delete files??
BLiZZaRD
08-10-2006, 09:24 AM
Hey I have a folder on my site that will collect user created files.
These files are a once use only file. What I was wondering is is there a script I can run with cron to once a day run through that folder only and delete any file of a certain extension (say .jpg)
so like it would be run at 5 p.m. server time and delete any and all *.jpg files in this one folder?
Does that make sense?
BLiZZaRD
08-10-2006, 11:01 AM
nevermind. I got it. I was using unset() instead of unlink().
For those after me, I am using this code and it has tested perfect with one file, and 40 files:
<?php
foreach (glob("*.jpg") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
unlink($filename);
}
?>
Why use PHP for this task?
rm /home/blizzard/images/temporary/*.jpg
BLiZZaRD
08-11-2006, 02:45 AM
Because I will be using cron so I don't have to go back to this folder ever again.
It is just a catch all folder for the created files. Once they are made, they are viewed, and then no longer needed.
So I make the php script, kick it off with cron, and poof, hassle free. :)
But equally you could just execute the above command with cron and remove the need for the PHP script :p
BLiZZaRD
08-11-2006, 08:26 AM
Yes, but then I wouldn't be learning PHP :p
blm126
08-11-2006, 02:46 PM
Yes, but then I wouldn't be learning PHP :p
I think the hardest part of learning any language is knowing when it's not the right tool for the job. :)
ItsMeOnly
08-11-2006, 03:19 PM
I think the hardest part of learning any language is knowing when it's not the right tool for the job. :)
That's called "beating the crap out of the man", but could actually agree more...:rolleyes:
Also you could just output the generated images directly from the PHP script that called them, and end the whole mess in the first place.
BLiZZaRD
08-12-2006, 07:51 AM
Also you could just output the generated images directly from the PHP script that called them, and end the whole mess in the first place.
That is true too, but that would defeat the entire purpose of the whole thing. I did think of that though.
I also found that command line code as well, but I still don't like those.
If I have to drive a nail into a 2X4 I can use a hammer, or a mallet. Both will get the job done, one easier than the other, but in the end, if the nail is driven it doesn't matter the way I got it in. :D
mburt
08-13-2006, 12:10 AM
If the nail goes in on an angle though, the board will split :)
Yes, but you really appear to be using a steak knife :)
It's interesting mburt decided to bump this thread today, because earlier I found the perfect answer to it (http://www.catb.org/~esr/writings/unix-koans/ten-thousand.html) in amongst ESR's lesser-known web oddities. :)
mburt
08-13-2006, 12:22 AM
Hmm.. I'm not sure how you can use a steak knife in place of a hammer... :)
You can if you bash it with the handle hard enough.
I've tried. :)
mburt
08-13-2006, 12:37 AM
(surfer-dude accent) Sweet!!
ItsMeOnly
08-13-2006, 12:41 AM
Oldie but goldie :)
> The Evolution of a Programmer
>
> -----------------------------
>
> High School/Jr.High
>
> ===================
>
> 10 PRINT "HELLO WORLD"
>
> 20 END
>
>
>
> First year in College
>
> =====================
>
> program Hello(input, output)
>
> begin
>
> writeln('Hello World')
>
> end.
>
>
>
> Senior year in College
>
> ======================
>
> (defun hello
>
> (print
>
> (cons 'Hello (list 'World))))
>
>
>
> New professional
>
> ================
>
> #include <stdio.h> void main(void)
>
> {
>
> char *message[] = {"Hello ", "World"};
>
> int i;
>
> for(i = 0; i < 2; ++i)
>
>
>
> printf("%s", message[i]);
>
> printf("\n");
>
> }
>
>
>
> Seasoned professional
>
> =====================
>
> #include <iostream.h> #include <string.h> class string
>
> {
>
> private:
>
> int size;
>
> char *ptr;
>
> public:
>
> string() : size(0), ptr(new char('\0')) {}
>
> string(const string &s) : size(s.size)
>
> {
>
> ptr = new char[size + 1];
>
> strcpy(ptr, s.ptr);
>
> }
>
> ~string()
>
> {
>
> delete [] ptr;
>
> }
>
> friend ostream &operator <<(ostream &, const string &);
>
>
>
> string &operator=(const char *);
>
>
>
> };
>
>
>
> ostream &operator<<(ostream &stream, const string &s)
>
> {
>
> return(stream << s.ptr);
>
> }
>
>
>
> string &string::operator=(const char *chrs)
>
> {
>
> if (this != &chrs)
>
> {
>
> delete [] ptr;
>
> size = strlen(chrs);
>
> ptr = new char[size + 1];
>
> strcpy(ptr, chrs);
>
> }
>
> return(*this);
>
> }
>
>
>
> int main()
>
> {
>
> string str;
>
> str = "Hello World";
>
> cout << str << endl;
>
> return(0);
>
> }
>
>
>
> Master Programmer
>
> =================
>
> [
>
> uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
>
>
>
> ]
>
> library LHello
>
> {
>
> // bring in the master library
>
> importlib("actimp.tlb");
>
> importlib("actexp.tlb");
>
> // bring in my interfaces
>
> #include "pshlo.idl"
>
> [
>
> uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
>
> ]
>
>
>
> cotype THello
>
> {
>
> interface IHello;
>
> interface IPersistFile;
>
> };
>
> };
>
> [
>
> exe,
>
> uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
>
> ]
>
> module CHelloLib
>
> {
>
> // some code related header files
>
> importheader(<windows.h>);
>
> importheader(<ole2.h>);
>
> importheader(<except.hxx>);
>
>
>
> importheader("pshlo.h");
>
> importheader("shlo.hxx");
>
> importheader("mycls.hxx");
>
> // needed typelibs
>
> importlib("actimp.tlb");
>
> importlib("actexp.tlb");
>
> importlib("thlo.tlb");
>
> [
>
> uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
>
> aggregatable
>
> ]
>
> coclass CHello
>
> {
>
> cotype THello;
>
> };
>
> };
>
>
>
> #include "ipfix.hxx"
>
> extern HANDLE hEvent;
>
> class CHello : public CHelloBase
>
> {
>
> public:
>
> IPFIX(CLSID_CHello);
>
> CHello(IUnknown *pUnk);
>
>
>
> ~CHello();
>
> HRESULT __stdcall PrintSz(LPWSTR pwszString);
>
> private:
>
> static int cObjRef;
>
> };
>
>
>
> #include <windows.h> #include <ole2.h> #include <stdio.h>
> #include <stdlib.h> #include "thlo.h"
>
> #include "pshlo.h"
>
> #include "shlo.hxx"
>
> #include "mycls.hxx"
>
> int CHello::cObjRef = 0;
>
> CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
>
> {
>
> cObjRef++;
>
> return;
>
> }
>
> HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString)
>
> {
>
> printf("%ws\n", pwszString);
>
> return(ResultFromScode(S_OK));
>
>
>
> }
>
> CHello::~CHello(void)
>
> {
>
> // when the object count goes to zero, stop the server
>
> cObjRef--;
>
> if( cObjRef == 0 )
>
> PulseEvent(hEvent);
>
> return;
>
> }
>
>
>
>
>
> #include <windows.h> #include <ole2.h> #include "pshlo.h"
>
> #include "shlo.hxx"
>
> #include "mycls.hxx"
>
> HANDLE hEvent;
>
> int _cdecl main(
>
> int argc,
>
> char * argv[])
>
> {
>
> ULONG ulRef;
>
> DWORD dwRegistration;
>
> CHelloCF *pCF = new CHelloCF();
>
> hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
>
> // Initialize the OLE libraries
>
> CoInitializeEx(NULL, COINIT_MULTITHREADED);
>
>
>
> CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
>
> REGCLS_MULTIPLEUSE, &dwRegistration);
>
> // wait on an event to stop
>
> WaitForSingleObject(hEvent, INFINITE);
>
> // revoke and release the class object
>
> CoRevokeClassObject(dwRegistration);
>
> ulRef = pCF->Release();
>
> // Tell OLE we are going away.
>
> CoUninitialize();
>
> return(0);
>
> }
>
>
>
> extern CLSID CLSID_CHello;
>
> extern UUID LIBID_CHelloLib;
>
> CLSID CLSID_CHello = { /* > 573F891-CFEE-101A-9A9F-00AA00342820 */
>
> 0x2573F891,
>
>
>
> 0xCFEE,
>
> 0x101A,
>
> { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
>
> };
>
> UUID LIBID_CHelloLib = { /* > 573F890-CFEE-101A-9A9F-00AA00342820 */
>
> 0x2573F890,
>
> 0xCFEE,
>
> 0x101A,
>
> { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
>
> };
>
>
>
> #include <windows.h> #include <ole2.h> #include <stdlib.h>
> #include <string.h> #include <stdio.h> #include "pshlo.h"
>
> #include "shlo.hxx"
>
> #include "clsid.h"
>
> int _cdecl main(
>
> int argc,
>
> char * argv[]) {
>
> HRESULT hRslt;
>
>
>
> IHello *pHello;
>
> ULONG ulCnt;
>
> IMoniker * pmk;
>
> WCHAR wcsT[_MAX_PATH];
>
> WCHAR wcsPath[2 * _MAX_PATH];
>
> // get object path
>
> wcsPath[0] = '\0';
>
> wcsT[0] = '\0';
>
> if( argc > 1) {
>
> mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
>
> wcsupr(wcsPath);
>
> }
>
> else {
>
> fprintf(stderr, "Object path must be specified\n");
>
> return(1);
>
> }
>
> // get print string
>
> if(argc > 2)
>
> mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
>
> else
>
> wcscpy(wcsT, L"Hello World");
>
>
>
> printf("Linking to object %ws\n", wcsPath);
>
> printf("Text String %ws\n", wcsT);
>
> // Initialize the OLE libraries
>
> hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
>
> if(SUCCEEDED(hRslt)) {
>
> hRslt = CreateFileMoniker(wcsPath, &pmk);
>
> if(SUCCEEDED(hRslt))
>
> hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);
>
> if(SUCCEEDED(hRslt)) {
>
> // print a string out
>
> pHello->PrintSz(wcsT);
>
> Sleep(2000);
>
> ulCnt = pHello->Release();
>
> }
>
> else
>
> printf("Failure to connect, status: %lx", hRslt);
>
>
>
> // Tell OLE we are going away.
>
> CoUninitialize();
>
> }
>
> return(0);
>
> }
>
>
>
> Apprentice Hacker
>
> ===================
>
> #!/usr/local/bin/perl
>
> $msg="Hello, world.\n";
>
> if ($#ARGV >= 0) {
>
> while(defined($arg=shift(@ARGV))) {
>
> $outfilename = $arg;
>
> open(FILE, ">" . $outfilename) || die "Can't write $arg: > !\n";
>
> print (FILE $msg);
>
> close(FILE) || die "Can't close $arg: $!\n";
>
> }
>
> } else {
>
> print ($msg);
>
> }
>
> 1;
>
>
>
> Experienced Hacker
>
> ===================
>
> #include <stdio.h> #define S "Hello, World\n"
>
> main(){exit(printf(S) == strlen(S) ? 0 : 1);}
>
>
>
> Seasoned Hacker
>
> ===================
>
> % cc -o a.out ~/src/misc/hw/hw.c
>
> % a.out
>
>
>
> Guru Hacker
>
> ===================
>
> % cat
>
> Hello, world.
>
> ^D
>
>
>
> New Manager
>
> ===================
>
> 10 PRINT "HELLO WORLD"
>
> 20 END
>
>
>
> Middle Manager
>
> ===================
>
> mail -s "Hello, world." bob@b12 Bob, could you please write me a
> program that prints "Hello, > orld."?
>
> I need it by tomorrow.
>
> ^D
>
>
>
> Senior Manager
>
> ===================
>
> % zmail jim
>
> I need a "Hello, world." program by this afternoon.
>
>
>
> Chief Executive
>
> ===================
>
> % letter
>
> letter: Command not found.
>
> % mail
>
> To: ^X ^F ^C
>
>
>
> % help mail
>
> help: Command not found.
>
> % damn!
>
> !: Event unrecognized
>
> % logout
mburt
08-13-2006, 12:44 AM
What is that, C++?
ItsMeOnly
08-13-2006, 12:48 AM
starting from beginning:
BASIC
Pascal
Lisp
C
C++
MSVC
Perl
BastarC :)
Magic
Wisdom
Deevolution
mburt
08-13-2006, 12:49 AM
Ah, I see.
Lol, no way should a master programmer still be including <windows.h>. :p
BLiZZaRD
08-13-2006, 05:15 AM
:D and all of this because I wanted to do something in php... :rolleyes:
mwinter
08-13-2006, 02:07 PM
Oldie but goldie :)
I know it's only a bit of fun, but I'd wonder why a seasoned professional would write a string object rather than using std::string, particularly as the wheel has been re-invented square, invoking undefined behaviour. :p Or is that the point? *shrugs*
As for that COM object...gagh!
I did enjoy the "Chief Executive", though. :D
and all of this because I wanted to do something in php...
Yup. It's all your fault. :)
Mike
I know it's only a bit of fun, but I'd wonder why a seasoned professional would write a string object rather than using std::string, particularly as the wheel has been re-invented square, invoking undefined behaviour.Maybe stdlib hadn't been standardised yet. :p
As for that COM object...gagh!I really must learn to use COM at some point. I hate the thought of it, but I know I'm going to need it somewhere on down the line.
BLiZZaRD
08-14-2006, 06:56 PM
Yup. It's all your fault. :)
My mom always said I would grow up to be a somebody! I doubt "instigator" was on her list though ROTF
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.