All pastes #99062 Raw Edit

saivert

public php v1 · immutable
#99062 ·published 2006-07-25 01:05 UTC
rendered paste body
<?php/* Script to clean up filenames** Written by Saivert*/if ($argc == 1 || !glob($argv[1]) ) {?>Filename cleaner scriptWritten by Saivert 2006Usage: hmm.php <filename> [switches]filename - Files to rename, supports wildcardsswitches:  -t    Test mode, does not rename  -s    Silent mode. Does not display output except errors  <?phpexit(0);}foreach (glob('*.m4a', GLOB_NOSORT) as $file) {	// Fjern spornummer fra begynnelsen	$newname = preg_replace('/^\d{2}\ /', '', $file);	// Kjør urldecode på filnavnet	$newname = urldecode($newname);	if (!findswitch('^-s$')) {		print "Renaming $file\n";		print "TO: $newname\n";	}	if (!findswitch('^-t$'))		rename($file, $newname);}/* Nice function to check if a switch is passed on the command line** $switchtofind is a regex pattern*/function findswitch($switchtofind) {	global $argv;	$found = false;	foreach($argv as $switch) {		if (eregi($switchtofind, $switch)) {			$found = true;			break;		}	}	return $found;}?>