# Thread: schedule to delete files

1. Junior Coders
Join Date
Jul 2006
Posts
21
Thanks
0
Thanked 0 Times in 0 Posts

## schedule to delete files

Hi everyone,

my server have to delete image files which were created 1 days ago. I intend to implement this feature by using "Scheduled Tasks" in windows XP, so that it can runs automatically everyday.

Here my problem come, I can't find suitable batch file(.bat) for that. Do you guys have any batch file to implement that? Or do you have other ideas without using "Scheduled Tasks"?

Thanks for help

ps: beside batch file, can we run php script automatically? I have try once but it cannot work(since we cannot use IE to execute php file directly)

2. php can only be run when a request is sent to the server for the page.
You could add a code like this to all (or some/one) of your pages:

<?php
if ($day = "new") { include("cleanup.php");$day = "old";
}

Where the variable $day is set to new if the current date is "new", and not "old". In a practical example, you'd compare the date to that of one stored in a database/text file (or even the creation time of a file on the server, like one of the images, IF there is one you know will always be there, or something), then check if that value is the same as that of the current date. Then the included "cleanup.php" page would have the "delete all images" function (look at php.net, shouldn't be too hard). Then you want to set the "day" to "old, whether by changing the value in the database, or something else. That way, it won't run again on the next load. OR, you could just write the cleanup.php page so it deletes anything more than 24 hours old. That's fairly easy too. Then just include that on each page, no if needed. 3. Junior Coders Join Date Jul 2006 Posts 21 Thanks 0 Thanked 0 Times in 0 Posts thanks. The problem solved. I have add program file of Internet Explorer into schedule, and the homepage set to file delete page. 4. Actually, somewhere on your server you'll probably find an executable called "php.exe". This can be used to run PHP scripts directly from the command line. Simply supply the script as an argument. 5. Elite Coders Join Date Dec 2004 Location UK Posts 2,358 Thanks 0 Thanked 0 Times in 0 Posts Originally Posted by djr33 You could add a code like this to all (or some/one) of your pages: <?php if ($day = "new") {
include("cleanup.php");
\$day = "old";
}
One could, though it would add overhead to every request. As such, performing scheduled tasks like this should be avoided whenever a cron (or similar) service is available.

Originally Posted by Twey
Actually, somewhere on your server you'll probably find an executable called "php.exe". This can be used to run PHP scripts directly from the command line.
The OP should be aware that there are several PHP executables available, depending on the version of PHP installed.

In PHP 4, there is a php.exe executable in the cli subdirectory (CLI is an acronym for Command Line Interface). The php.exe executable in the root installation directory is the CGI (Common Gateway Interface) version, which intended for use with a server.

In PHP 5, the situation changes. The CGI version has been renamed php-cgi.exe, and the CLI version can now be found in the root installation directory. There's also a new php-win.exe executable which doesn't cause the console window to open.

The install.txt file contains a description of this in the Manual Installation Steps section, and the PHP manual contains information about running PHP from the command line.

Mike

6. Junior Coders
Join Date
Jul 2006
Posts
21
Thanks
0
Thanked 0 Times in 0 Posts
Originally Posted by mwinter
One could, though it would add overhead to every request. As such, performing scheduled tasks like this should be avoided whenever a cron (or similar) service is available.

The OP should be aware that there are several PHP executables available, depending on the version of PHP installed.

In PHP 4, there is a php.exe executable in the cli subdirectory (CLI is an acronym for Command Line Interface). The php.exe executable in the root installation directory is the CGI (Common Gateway Interface) version, which intended for use with a server.

In PHP 5, the situation changes. The CGI version has been renamed php-cgi.exe, and the CLI version can now be found in the root installation directory. There's also a new php-win.exe executable which doesn't cause the console window to open.

The install.txt file contains a description of this in the Manual Installation Steps section, and the PHP manual contains information about running PHP from the command line.

Mike
totally lost........-.-|

7. Don't do it. It's slow. Use the php.exe executable instead, which can be found in root/cli in PHP4 (where root is the directory in which you installed PHP), or in the top directory in which you installed PHP for PHP5.

8. Junior Coders
Join Date
Jul 2006
Posts
21
Thanks
0
Thanked 0 Times in 0 Posts
I once double click on php.exe but it do nothing?

can i know the dos command (or any other command) to run php script through php.exe?

9. Elite Coders
Join Date
Dec 2004
Location
UK
Posts
2,358
Thanks
0
Thanked 0 Times in 0 Posts
Originally Posted by s00263668
I once double click on php.exe but it do nothing?
The PHP executable expects command line arguments to instruct it what do to. It's not like many programs that display a user interface; it's not that sort of software.

can i know the dos command (or any other command) to run php script through php.exe?
Run:

&#160;&#160;/path/to/php -f /path/to/file

For example, I've installed PHP to D:\PHP\5.1.4, so to run a file called X:\example.php, the command would be:

&#160;&#160;D:\PHP\5.1.4\php -f X:\example.php

Be aware that the working directory (the directory used to resolve path names like ..\dir) isn't changed by the PHP executable. You either have to:

• set the directory before running the script,
• use the chdir function within the script to change the directory at run-time, or
• use full path names (like X:\path\to\file), avoiding the issue entirely.

Hope that helps,
Mike

10. Junior Coders
Join Date
Jul 2006
Posts
21
Thanks
0
Thanked 0 Times in 0 Posts
thanks for help

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•