Tag Archive for remove

Recursively delete .LCK files from directory.

find . -type f -name "*.LCK" -exec rm -f {} ;

source

Remove an item of array

// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};

source

Clean Out A Folder – Remove A Folders Complete Contents

<?php

function emptyDir($path) {

// INITIALIZE THE DEBUG STRING
$debugStr = '';
$debugStr .= "Deleting Contents Of: $path<br /><br />";

// PARSE THE FOLDER
if ($handle = opendir($path)) {

while (false !== ($file = readdir($handle))) {

if ($file != "." && $file != "..") {

// IF IT"S A FILE THEN DELETE IT
if(is_file($path."/".$file)) {

if(unlink($path."/".$file)) {
$debugStr .= "Deleted File: ".$file."<br />";
}

} else {

// IT IS A DIRECTORY
// CRAWL THROUGH THE DIRECTORY AND DELETE IT'S CONTENTS

if($handle2 = opendir($path."/".$file)) {

while (false !== ($file2 = readdir($handle2))) {

if ($file2 != "." && $file2 != "..") {
if(unlink($path."/".$file."/".$file2)) {
$debugStr .= "Deleted File: $file/$file2<br />";
}
}

}

}

if(rmdir($path."/".$file)) {
$debugStr .= "Directory: ".$file."<br />";
}

}

}

}

}
return $debugStr;
}

?>

source

removeSvn

#!/usr/bin/python

import os
import sys

top = sys.argv[1]

for root, dirs, files in os.walk(top):
if '.svn' in dirs:
os.system('rm -rf '+os.path.join(root,'.svn'))

source

Remove extra returns from text

descriptionText.text = description.replace(/r/g, '');

source

Remove Folders from a Directory

rm -rf directory/{folder_a,folder_b}

source

Recursively remove .svn directories

find . -regex '.*.svn' -exec rm -rf "{}" ;

source

Strip punctuation from text.

function strip_punctuation( $text )
{
$urlbrackets    = '[]()';
$urlspacebefore = ':;'_*%@&?!' . $urlbrackets;
$urlspaceafter  = '.,:;'-_*@&/\?!#' . $urlbrackets;
$urlall         = '.,:;'-_*%@&/\?!#' . $urlbrackets;

$specialquotes  = ''"*<>';

$fullstop       = 'x{002E}x{FE52}x{FF0E}';
$comma          = 'x{002C}x{FE50}x{FF0C}';
$arabsep        = 'x{066B}x{066C}';
$numseparators  = $fullstop . $comma . $arabsep;

$numbersign     = 'x{0023}x{FE5F}x{FF03}';
$percent        = 'x{066A}x{0025}x{066A}x{FE6A}x{FF05}x{2030}x{2031}';
$prime          = 'x{2032}x{2033}x{2034}x{2057}';
$nummodifiers   = $numbersign . $percent . $prime;

return preg_replace(
array(
// Remove separator, control, formatting, surrogate,
// open/close quotes.
'/[p{Z}p{Cc}p{Cf}p{Cs}p{Pi}p{Pf}]/u',
// Remove other punctuation except special cases
'/p{Po}(?<![' . $specialquotes .
$numseparators . $urlall . $nummodifiers . '])/u',
// Remove non-URL open/close brackets, except URL brackets.
'/[p{Ps}p{Pe}](?<![' . $urlbrackets . '])/u',
// Remove special quotes, dashes, connectors, number
// separators, and URL characters followed by a space
'/[' . $specialquotes . $numseparators . $urlspaceafter .
'p{Pd}p{Pc}]+((?= )|$)/u',
// Remove special quotes, connectors, and URL characters
// preceded by a space
'/((?<= )|^)[' . $specialquotes . $urlspacebefore . 'p{Pc}]+/u',
// Remove dashes preceded by a space, but not followed by a number
'/((?<= )|^)p{Pd}+(?![p{N}p{Sc}])/u',
// Remove consecutive spaces
'/ +/',
),
' ',
$text );
}

source

Clean Word HTML using Regular Expressions

function cleanHTML($html) {
/// <summary>
/// Removes all FONT and SPAN tags, and all Class and Style attributes.
/// Designed to get rid of non-standard Microsoft Word HTML tags.
/// </summary>
// start by completely removing all unwanted tags

$html = ereg_replace("<(/)?(font|span|del|ins)[^>]*>","",$html);

// then run another pass over the html (twice), removing unwanted attributes

$html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|'[^']*'|[^>]+)([^>]*)>","<1>",$html);
$html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|'[^']*'|[^>]+)([^>]*)>","<1>",$html);

return $html
}

source

Add and Remove Elements with JavaScript (reprise)

var Dom = { get: function(el) { if (typeof el === 'string') { return document.getElementById(el); } else { return el; } }, add: function(el, dest) { var el = this.get(el); var dest = this.get(dest); dest.appendChild(el); }, remove: function(el) { var el = this.get(el); el.parentNode.removeChild(el); } }; var Event = { add: function() { if (window.addEventListener) { return function(el, type, fn) { Dom.get(el).addEventListener(type, fn, false); }; } else if (window.attachEvent) { return function(el, type, fn) { var f = function() { fn.call(Dom.get(el), window.event); }; Dom.get(el).attachEvent('on' + type, f); }; } }() };

source