<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Joseph Abraham]]></title><description><![CDATA[Joseph Abraham]]></description><link>https://josephabraham.dev</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 09:33:02 GMT</lastBuildDate><atom:link href="https://josephabraham.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Powershell Script: Get-ChildItem]]></title><description><![CDATA[In this article, I want to demonstrate the use of the PowerShell cmdlet: Get-ChildItem.
Let's consider this scenario.
Imagine you need to get the list of file names in a folder to a CSV or flat file. Sounds simple, right? Yes, it is, but what if the ...]]></description><link>https://josephabraham.dev/powershell-scripts-get-childitem</link><guid isPermaLink="true">https://josephabraham.dev/powershell-scripts-get-childitem</guid><category><![CDATA[Powershell]]></category><category><![CDATA[get-childitem]]></category><category><![CDATA[filenames]]></category><dc:creator><![CDATA[Joseph Abraham]]></dc:creator><pubDate>Wed, 08 Jun 2016 13:06:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/rfg4l6_lu3c/upload/1f27858aff86e9998d6c6b336f64e4c3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, I want to demonstrate the use of the <strong>PowerShell</strong> cmdlet: <code>Get-ChildItem</code>.</p>
<p>Let's consider this scenario.</p>
<p>Imagine you need to get the list of file names in a folder to a CSV or flat file. Sounds simple, right? Yes, it is, but what if the folder contains 100’s of files? Well, it’s not that simple.</p>
<p>And what if you don’t want the entire filename? Instead, read the characters before a ‘-‘ and pad some spaces or zero’s on each line. Well, <strong>PowerShell</strong> comes to our rescue in this case.</p>
<h3 id="heading-reading-files-in-a-folder-and-exporting-it-to-a-file-using-powershell-scripts">Reading files in a folder and exporting it to a file using Powershell scripts</h3>
<ul>
<li>The first step is to get the list of file names into an array.</li>
</ul>
<pre><code class="lang-powershell"><span class="hljs-variable">$files</span> = (<span class="hljs-built_in">Get-ChildItem</span> <span class="hljs-literal">-Path</span> \<span class="hljs-number">192.168</span>.<span class="hljs-number">0.10</span>\ToBeLoadedPics <span class="hljs-literal">-Filter</span> *.jpg)
</code></pre>
<details><summary>Get-ChildItem</summary><div data-type="detailsContent">The Get-ChildItem cmdlet gets all the items in the folder. You can give a -Filter parameter to specify any specific file type.</div></details>

<ul>
<li>The next step is to loop through this array <strong>$files</strong> and populate each line you need into an array.</li>
</ul>
<pre><code class="lang-powershell"><span class="hljs-variable">$result</span> = <span class="hljs-selector-tag">@</span>();
<span class="hljs-keyword">for</span>(<span class="hljs-variable">$i</span>=<span class="hljs-number">0</span>;<span class="hljs-variable">$i</span> <span class="hljs-operator">-lt</span> <span class="hljs-variable">$files</span>.Count;<span class="hljs-variable">$i</span>++)
{
  <span class="hljs-variable">$file</span> = <span class="hljs-variable">$files</span>[<span class="hljs-variable">$i</span>]
  <span class="hljs-variable">$row</span> = <span class="hljs-variable">$file</span>.Name.Substring(<span class="hljs-number">0</span>,<span class="hljs-variable">$file</span>.Name.IndexOf(<span class="hljs-string">"-"</span>));
  <span class="hljs-variable">$outline</span> = <span class="hljs-string">"00<span class="hljs-variable">$</span>{row} ,<span class="hljs-variable">$</span>{file}"</span>.PadRight(<span class="hljs-number">94</span>,<span class="hljs-string">' '</span>);
  <span class="hljs-variable">$result</span> += <span class="hljs-variable">$outline</span>;
}
</code></pre>
<ul>
<li>So now we have the result in the array <strong>$result</strong>. We can write it to a CSV file, text, or any file you like. We can achieve that by using the <strong>Out-File</strong> cmdlet.</li>
</ul>
<pre><code class="lang-powershell"><span class="hljs-variable">$result</span> | <span class="hljs-built_in">Out-File</span> \<span class="hljs-number">192.168</span>.<span class="hljs-number">0.10</span>\Output\LoadedPics.csv
</code></pre>
]]></content:encoded></item></channel></rss>