<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>..::\\ www.christiano.ch //::.. &#187; Get-ChildItem</title>
	<atom:link href="http://www.christiano.ch/wordpress/tag/get-childitem/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christiano.ch/wordpress</link>
	<description>christiano.ch blog - personal knowledge base, news, memoires et cetera</description>
	<lastBuildDate>Fri, 06 Jan 2012 15:28:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<meta xmlns="http://www.w3.org/1999/xhtml" name="robots" content="noindex,follow" />
		<item>
		<title>PowerShell: Delete specific files recursively / recursive</title>
		<link>http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/</link>
		<comments>http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 12:26:14 +0000</pubDate>
		<dc:creator>christian</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Get-ChildItem]]></category>
		<category><![CDATA[Remove-Item]]></category>
		<category><![CDATA[Where-Object]]></category>

		<guid isPermaLink="false">http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/</guid>
		<description><![CDATA[Okay, this post I&#8217;m going to write down for my personal notes but also for you.. Ever needed to delete a specific file, in my case in need to delete (remove-item) all *.pdb files in one of my Visual Studio &#8230; <a href="http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<table border="0" cellspacing="0" cellpadding="2" width="675">
<tbody>
<tr>
<td valign="top" width="644">Okay, this post I&#8217;m going to write down for my personal notes but also for you..          <br />Ever needed to delete a specific file, in my case in need to delete (remove-item) all *.pdb files in one of my Visual Studio Solution.. recursive of course.           <br />To get a list of Files use the <strong><em>Get-ChildItem</em></strong> CmdLet. Extend that command using the <strong><em>–rec</em></strong> or <strong><em>–recurse</em></strong> parameter – so you’ll get all the files recursively, starting from the current path / directory.</td>
<td valign="top" width="30"><a href="http://www.christiano.ch/wordpress/wp-content/uploads/2010/02/Logo_PowerShell.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo_PowerShell" border="0" alt="Logo_PowerShell" src="http://www.christiano.ch/wordpress/wp-content/uploads/2010/02/Logo_PowerShell_thumb.png" width="160" height="125" /></a> </td>
</tr>
</tbody>
</table>
<p> <span id="more-860"></span>
<p>Now, we don’t need all the file, but all the files with a specific extension. We’ll use the <strong><em>Where-Object </em></strong>to achieve this. Well if you do <strong><em>Get-ChildItem</em></strong> you’ll get something like:</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem </strong></em></p>
<p><em>&#160;&#160;&#160; Directory: D:\DEMO </em></p>
<p><em>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-      <br />d&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:16&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; DEMO Folder      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:17&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 18 someFile.ext </em></p>
<p><em>PS D:\DEMO&gt;</em></p>
<p>&#160;</p>
<p>So, how to get only files with a specific extension? Easy, using <strong><em>Get-Member </em></strong>we can list all properties of <strong><em>Get-ChildItem</em></strong>.</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem | Get-Member </strong></em></p>
<p><em>&#160;&#160; TypeName: System.IO.DirectoryInfo </em></p>
<p><em>Name&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; MemberType&#160;&#160;&#160;&#160; Definition     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;-      <br />Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; CodeProperty&#160;&#160; System.String Mode{get=Mode;}      <br />Create&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Method&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.Void Create(System.Security.AccessControl.DirectorySecurity director&#8230;      <br />&#8230;      <br />&#8230;      <br /><strong>Extension&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Property&#160;&#160;&#160;&#160;&#160;&#160; System.String Extension {get;}</strong></em>    <br /><em>FullName&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Property&#160;&#160;&#160;&#160;&#160;&#160; System.String FullName {get;}     <br />&#8230;      <br />&#8230; </em></p>
<p><em>PS D:\DEMO&gt;</em></p>
<p>&#160;</p>
<p>When we want to search for a specific File Type, the Extension Property comes in very handy. </p>
<p>So, to get a list of all, let’s say *.tmp files recursively, we’ll write:</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem -Rec | Where {$_.Extension -match &quot;tmp&quot;} </strong></em></p>
<p><em>&#160;&#160;&#160; Directory: D:\DEMO </em></p>
<p><em>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:22&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 12 demo.tmp </em></p>
<p><em>&#160;&#160;&#160; Directory: D:\DEMO\DEMO Folder </em></p>
<p><em>Mode&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LastWriteTime&#160;&#160;&#160;&#160; Length Name     <br />&#8212;-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#8212;&#8212;&#8212;&#8212;-&#160;&#160;&#160;&#160; &#8212;&#8212; &#8212;-      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:22&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 12 dem32.tmp      <br />-a&#8212;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 19.02.2010&#160;&#160;&#160;&#160; 13:22&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 12 demo2.tmp </em></p>
<p><em>PS D:\DEMO&gt;</em></p>
<p>&#160;</p>
<p>Now, let’s delete all of these *.tmp files using Remove-Item</p>
<p><em><strong>PS D:\DEMO&gt; Get-ChildItem -Rec | Where {$_.Extension -match &quot;tmp&quot;} | Remove-Item</strong></em></p>
<p>and they are all gone!</p>
<div class="tweetthis" style="text-align:left;"><p> <a class="tt" href="http://twitter.com/intent/tweet?text=PowerShell%3A+Delete+specific+files+recursively+%2F+recursive+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D860" title="Post to Twitter"><img class="nothumb" src="http://www.christiano.ch/wordpress/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/intent/tweet?text=PowerShell%3A+Delete+specific+files+recursively+%2F+recursive+http%3A%2F%2Fchristiano.ch%2Fwordpress%2F%3Fp%3D860" title="Post to Twitter">Tweet This Post</a></p></div>]]></content:encoded>
			<wfw:commentRss>http://www.christiano.ch/wordpress/2010/02/19/powershell-delete-specific-files-recursively-recursive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

