How to delete a file or folder in Powershell

To delete a file or Folder in Powershell you can use the following snippet.

Sample Powershell

if you want to delete a file use

remove-item -path "C:\Users\Codesnippets\Desktop\Test.xml" -force -recurse

if you want to delete a folder use

remove-item -path "C:\Users\Codesnippets\Desktop\Folder1" -force -recurse

for more informations see Using the Remove-Item Cmdlet

Please rate this snippet

IndexOf method for Javascript

With the snippet below you can use the IndexOf method for Javascript.

Sample JS

Array.prototype.IndexOf = Array.prototype.IndexOf || function (element) {
    for (var i=0; i < this.length; i++) {
        if(this[i] === element) return i;
    }
    return -1;
};

Please rate this snippet

How to check if array contains string case insensitive in PHP

To check if array contains string case insensitive in PHP you can use the following snippet.

function ArrayContainsStringCaseInsensitve($searchString, $array){
    foreach($array as $element){
        if(strcasecmp($searchString, $element)==0){
            return true;
        }
    }
    return false;
}

Please rate this snippet

How to remove all children from XNode in C# and VB.NET

To remove all children from XNode in C# and VB.NET you can use the following snippet.

Sample C#

public static XDocument RemoveAllChildren(XNode xNode)
{
	if (xNode.IsNull() || String.IsNullOrEmpty(xNode.ToString()))
	{
		return null;
	}
	var xElement = xNode.ToXElement();
	xElement.RemoveNodes();
	return XDocument.Parse(xElement.ToString());
}

Sample VB.NET

Public Shared Function RemoveAllChildren(xNode As XNode) As XDocument
	If xNode.IsNull() OrElse [String].IsNullOrEmpty(xNode.ToString()) Then
		Return Nothing
	End If
	Dim xElement = xNode.ToXElement()
	xElement.RemoveNodes()
	Return XDocument.Parse(xElement.ToString())
End Function

Please rate this snippet

How to remove all children from XMLNode in C# and VB.NET

To remove all children from XMLNode in C# and VB.NET you can use the follwing snippet.

Sample C#

public static XmlDocument RemoveAllChildren(XmlNode xmlNode)
{
	if (xmlNode.IsNull() || String.IsNullOrEmpty(xmlNode.ToString()))
	{
		return null;
	}
	while (xmlNode.HasChildNodes)
	{
		xmlNode.RemoveChild(xmlNode.FirstChild);
	}
	return xmlNode.OuterXml.ToXmlDocument();
}

Sample VB.NET

Public Shared Function RemoveAllChildren(xmlNode As XmlNode) As XmlDocument
	If xmlNode.IsNull() OrElse [String].IsNullOrEmpty(xmlNode.ToString()) Then
		Return Nothing
	End If
	While xmlNode.HasChildNodes
		xmlNode.RemoveChild(xmlNode.FirstChild)
	End While
	Return xmlNode.OuterXml.ToXmlDocument()
End Function

Please rate this snippet