<?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>Ad hoc Geek &#187; cmd</title>
	<atom:link href="http://www.adhocgeek.com/tag/cmd/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.adhocgeek.com</link>
	<description>Approaching geekery in an ad hoc and improvisational manner.</description>
	<lastBuildDate>Fri, 30 Sep 2011 09:43:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Windows command shell fun</title>
		<link>http://www.adhocgeek.com/2009/08/windows-command-shell-fun/</link>
		<comments>http://www.adhocgeek.com/2009/08/windows-command-shell-fun/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 14:51:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[batch script]]></category>
		<category><![CDATA[cmd]]></category>
		<category><![CDATA[dos]]></category>

		<guid isPermaLink="false">http://www.adhocgeek.com/?p=88</guid>
		<description><![CDATA[(only for slightly bizarre/masochistic senses of fun) I&#8217;ve been out on a client site for a month or two and haven&#8217;t had time to update a lot. Now that I&#8217;m back in the office I decided to ease myself into things slowly by going through my usual backup routine and incidentally tidying up my music [...]]]></description>
			<content:encoded><![CDATA[<p>(only for slightly bizarre/masochistic senses of fun)</p>
<p>I&#8217;ve been out on a client site for a month or two and haven&#8217;t had time to update a lot. Now that I&#8217;m back in the office I decided to ease myself into things slowly by going through my usual backup routine and incidentally tidying up my music collection.</p>
<p>I had discovered over the last few months that bits of my collection disappeared when I imported into iTunes, because they were originally ripped into ogg vorbis format &#8211; iTunes doesn&#8217;t understand ogg (at least, not by default), and because I&#8217;ve got around 23GB of music, I hadn&#8217;t noticed a few hundred missing songs until now.</p>
<p>Converting them in place was fairly simple with CDex, but once I&#8217;d done this I needed to move, check, then delete the (now) extraneous ogg files. So, what command could I issue to search through a list of directories, find files of a particular extension and move them to a holding pen? This isn&#8217;t especially straight forward on the windows command line, but this is the batch file that eventually worked for me :</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #00b100; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">exist</span> oggfile.list <span style="color: #b1b100; font-weight: bold;">del</span> oggfile.list
<span style="color: #b1b100; font-weight: bold;">dir</span> /s /b *.ogg <span style="color: #33cc33;">&gt;&gt;</span> oggfile.list
<span style="color: #00b100; font-weight: bold;">for</span> /f &quot;delims=&quot; <span style="color: #33cc33;">%%</span><span style="color: #448888;">a</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #33cc33;">(</span>oggfile.list<span style="color: #33cc33;">)</span> <span style="color: #00b100; font-weight: bold;">do</span> <span style="color: #33cc33;">(</span><span style="color: #b1b100; font-weight: bold;">move</span> &quot;<span style="color: #33cc33;">%%</span><span style="color: #448888;">a</span>&quot; temp<span style="color: #33cc33;">)</span></pre></div></div>

<p>You can issue these as separate commands if you want, all that changes is the &#8220;%%a&#8221; becomes &#8220;%a&#8221; instead (I did it that way myself to begin with until I realised I wanted to find other, errant non-mp3 files as well). </p>
<p>If you want something more generic, being able to pass arguments to batch scripts means you can do this with files of any particular extension :</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;"><span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>&quot;==&quot;&quot; <span style="color: #00b100; font-weight: bold;">goto</span> :<span style="color: #b100b1; font-weight: bold;">EOF</span>
<span style="color: #b1b100; font-weight: bold;">echo</span> Finding and moving .<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span> files...
<span style="color: #00b100; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">exist</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>file.list <span style="color: #b1b100; font-weight: bold;">del</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>file.list
<span style="color: #b1b100; font-weight: bold;">dir</span> /s /b *.<span style="color: #33cc33;">%</span><span style="color: #448888;">1</span> <span style="color: #33cc33;">&gt;&gt;</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">1</span>file.list
<span style="color: #00b100; font-weight: bold;">for</span> /f &quot;delims=&quot; <span style="color: #33cc33;">%%</span><span style="color: #448888;">a</span> <span style="color: #00b100; font-weight: bold;">in</span> <span style="color: #33cc33;">(%</span><span style="color: #448888;">1</span>file.list<span style="color: #33cc33;">)</span> <span style="color: #00b100; font-weight: bold;">do</span> <span style="color: #33cc33;">(</span><span style="color: #b1b100; font-weight: bold;">move</span> &quot;<span style="color: #33cc33;">%%</span><span style="color: #448888;">a</span>&quot; temp<span style="color: #33cc33;">)</span></pre></div></div>

<p>Assuming you save this as finder.bat (there already is a find command), then to move all ogg files in a particular tree you would simply call :</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">C:\finder ogg</pre></div></div>

<p>I could probably go the whole hog and make the &#8220;temp&#8221; directory user-definable as well, but I think I&#8217;ve used the script a grand total of 3 times now and probably won&#8217;t touch it again.</p>
<p>It was fun to go old-school for a while. Dos batch commands are a lot more powerful than people realise, but they are somewhat arcane.</p>
<p>I recommend <a href="http://www.robvanderwoude.com/index.php">Rob van der Woude&#8217;s scripting pages</a> for anyone wanting to delve into this more deeply, I&#8217;ve used his reference pages quite a lot in the past and usually been able to solve the problem at hand. He also covers a lot of other scripting languages besides windows batch script.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adhocgeek.com/2009/08/windows-command-shell-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

