home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2003 April
/
Chip_2003-04_cd1.bin
/
zkuste
/
phpgtk
/
download
/
samples
/
porg.php
< prev
next >
Wrap
PHP Script
|
2002-08-25
|
3KB
|
100 lines
<?php
/*
* porg.php - PORG Organizes Real Good
*
* Author: Josh Sherman
* Purpose: Renames a directory of files based
*on a custom prefix. i.e. PORGn.*
* Usage: php -q porg.php
*/
if (!class_exists('gtk')) {
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
dl('php_gtk.dll');
else
dl('php_gtk.so');
}
function delete_event()
{
return false;
}
function destroy()
{
Gtk::main_quit();
}
function back_up()
{
global $dir_entry;
global $directory;
$directory = $dir_entry->get_text();
@mkdir("$directory/bkup", 0777);
if ($dir = @opendir("$directory")) {
while (($file = readdir($dir)) !== false) {
if ($file != "bkup" && substr($file, 0, 1) != "." && is_dir($file) == 0) {
if (@copy("$directory/$file", "$directory/bkup/$file")) {
unlink("$directory/$file");
}
}
}
closedir($dir);
}
rename_files();
}
function rename_files()
{
global $directory;
global $prefix;
global $prefix_entry;
global $check;
global $window;
$prefix = $prefix_entry->get_text();
$i = 0;
if ($dir = opendir("$directory/bkup")) {
while (($file = readdir($dir)) !== false) {
if (strlen($i) == 1) { $number = "000" . $i; }
if (strlen($i) == 2) { $number = "00" . $i; }
if (strlen($i) == 3) { $number = "0" . $i; }
$extension = substr(strrchr($file, "."), 1);
if ($file != "." && $file != ".." && $file != "bkup") {
if (@copy("$directory/bkup/$file", "$directory/$prefix$number.$extension")) {
if ($check->get_active() == 0) {
unlink("$directory/bkup/$file");
}
$i++;
}
}
}
closedir($dir);
}
if ($check->get_active() == 0) {
rmdir("$directory/bkup");
}
echo "\nall done!\n";
}
$window = &new GtkWindow();
$window->set_title('PORG');
$window->connect('destroy', 'destroy');
$window->connect('delete-event', 'delete_event');
$window->set_border_width(10);
$table = &new GtkTable(4, 2);
$table->set_row_spacings(4);
$table->set_col_spacings(4);
$window->add($table);
$dir_label = &new GtkLabel('Directory: ');
$table->attach($dir_label, 0, 1, 0, 1);
$prefix_label = &new GtkLabel('File Prefix: ');
$table->attach($prefix_label, 0, 1, 1, 2);
$dir_entry = &new GtkEntry();
$table->attach($dir_entry, 1, 2, 0, 1);
$prefix_entry = &new GtkEntry();
$table->attach($prefix_entry, 1, 2, 1, 2);
$check = &new GtkCheckButton('Backup Directory?');
$check->set_active(TRUE);
$table->attach($check, 1, 2, 2, 3);
$button = &new GtkButton('Rename Files');
$button->connect('clicked','back_up');
$table->attach($button, 0, 2, 3, 4);
$window->show_all();
Gtk::main();
?>