<?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; batch script</title>
	<atom:link href="http://www.adhocgeek.com/tag/batch-script/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>dtutil : Importing SSIS packages via batch scripting</title>
		<link>http://www.adhocgeek.com/2011/01/dtutil-importing-ssis-packages-via-batch-scripting/</link>
		<comments>http://www.adhocgeek.com/2011/01/dtutil-importing-ssis-packages-via-batch-scripting/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 17:09:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[batch script]]></category>
		<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[SSIS]]></category>

		<guid isPermaLink="false">http://www.adhocgeek.com/?p=193</guid>
		<description><![CDATA[Just a quick and simple task here. I got fed up of manually importing dtsx files into our SSIS file store so I looked into a scripting solution. This relies entirely on dtutil which is installed with SSIS. @echo off &#160; set root=My SSIS Packages set server=SSIS01 &#160; echo Importing Some Foo Packages &#160; set [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick and simple task here. I got fed up of manually importing dtsx files into our SSIS file store so I looked into a scripting solution. This relies entirely on <a href="http://msdn.microsoft.com/en-us/library/ms162820.aspx">dtutil</a> which is installed with SSIS.</p>

<div class="wp_syntax"><div class="code"><pre class="batch" style="font-family:monospace;">@echo off
&nbsp;
set root=My SSIS Packages
set server=SSIS01
&nbsp;
echo Importing Some Foo Packages
&nbsp;
set tmpFolder=Foo
dtutil /SourceServer %server%  /FExists SQL;&quot;\%root%\%tmpFolder%&quot;
if errorlevel=1 dtutil /SourceServer %server% /FCreate SQL;&quot;\%root_folder%&quot;;&quot;%tmpFolder%&quot;
&nbsp;
dtutil /File &quot;Foo1.dtsx&quot; /Encrypt SQL;&quot;\%root%\%tmpFolder%\Foo1&quot;;5 /DestServer %server% /Q
...</pre></div></div>

<p>This is pretty simple &#8211; it checks whether there&#8217;s a &#8220;Foo&#8221; folder under the root path &#8220;My SSIS Packages&#8221; on the destination SSIS instance, if not it creates the folder and then uploads the package. The only thing to note here is that I&#8217;m using /Encrypt rather than /Copy, this is the same as manually uploading and setting the protection level to &#8220;Rely on server storage and roles for access control&#8221; (essential if you&#8217;re uploading packages which will be scheduled to run under a different account to your development account).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.adhocgeek.com/2011/01/dtutil-importing-ssis-packages-via-batch-scripting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

