<?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>TechBlog &#187; Scripts</title>
	<atom:link href="http://techblog.byllemos.com/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.byllemos.com</link>
	<description>Accelerating into the Future with Wisdom about Technology! Ingrid Byllemos</description>
	<lastBuildDate>Tue, 05 Jan 2010 00:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Splitting files using Visual Basic Scripts</title>
		<link>http://techblog.byllemos.com/2008/05/splitting-files-using-visual-basic-scripts/</link>
		<comments>http://techblog.byllemos.com/2008/05/splitting-files-using-visual-basic-scripts/#comments</comments>
		<pubDate>Wed, 21 May 2008 20:02:35 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[Scripting.FileSystemObject]]></category>
		<category><![CDATA[vbs]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=69</guid>
		<description><![CDATA[<p>Do you occasionally need to split a file based on its content? </p>
<p>If yes &#8211; then this can be done quickly by using a Visual Basic Script and &#8220;Scripting.FileSystemObject&#8221;.</p>
<p>Lets take a closer look.<br />
<span id="more-69"></span><br />
First you&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Do you occasionally need to split a file based on its content? </p>
<p>If yes &#8211; then this can be done quickly by using a Visual Basic Script and &#8220;Scripting.FileSystemObject&#8221;.</p>
<p>Lets take a closer look.<br />
<span id="more-69"></span><br />
First you have to define your source file and destination file.</p>
<blockquote><p>
FileCount = 0<br />
DestFileName = &#8220;C:\destination&#8221;&#038;FileCount&#038;&#8221;.txt&#8221;</p>
<p>Set objFileSystemObject = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
Set objSource = objFileSystemObject.OpenTextFile(&#8220;C:\sourcefile.txt&#8221;, ForReading)<br />
Set objDestination = objFileSystemObject.CreateTextFile(DestFileName, True)
</p></blockquote>
<p>Next you have to run through the Source File and write it to destinations files.</p>
<blockquote><p>
&#8216;File Separator Mark<br />
NewFileContent = &#8220;&#8211;start&#8221;</p>
<p>&#8216;Run through the file<br />
Do Until objSource.AtEndOfStream<br />
<blankspace>&#8230;&#8230;</blankspace>&#8216;Read a line<br />
<blankspace>&#8230;&#8230;</blankspace>strLine = objSource.ReadLine</p>
<p><blankspace>&#8230;&#8230;</blankspace>&#8216;Check if a new file should be created<br />
<blankspace>&#8230;&#8230;</blankspace>If InStr(1, strLine, NewFileContent) > 0 Then<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace>&#8216;Close Previous File<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace>objDestination.Close<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace>Set objDestination = Nothing</p>
<p><blankspace>&#8230;&#8230;&#8230;..</blankspace>&#8216;Create New FileName<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace>FileCount = FileCount + 1<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace>DestFileName = &#8220;C:\destination&#8221;&#038;FileCount&#038;&#8221;.txt&#8221;</p>
<p><blankspace>&#8230;&#8230;&#8230;..</blankspace>&#8216;Create and Open New File<br />
<blankspace>&#8230;&#8230;&#8230;..</blankspace>Set objDestination = objFileSystemObject.CreateTextFile(DestFileName, True)<br />
<blankspace>&#8230;&#8230;</blankspace>End If</p>
<p><blankspace>&#8230;&#8230;</blankspace>&#8216;Write to the file<br />
<blankspace>&#8230;&#8230;</blankspace>objDestination.WriteLine (strLine)<br />
Loop
</p></blockquote>
<p>And the finally end by closing the open files</p>
<blockquote><p>
objSource.Close<br />
objDestination.Close</p>
<p>Set objSource = Nothing<br />
Set objDestination = Nothing<br />
Set objFileSystemObject = Nothing
</p></blockquote>
<p>In the above example a file looking like this</p>
<blockquote><p>
&#8211;start<br />
my first file<br />
&#8211;start<br />
my second file<br />
&#8211;start<br />
my third file
</p></blockquote>
<p>would be split in to the files:</p>
<blockquote><p>
destination1.txt containing:<br />
&#8211;start<br />
my first file
</p></blockquote>
<blockquote><p>
destination2.txt containing:<br />
&#8211;start<br />
my second file
</p></blockquote>
<blockquote><p>
destination3.txt containing:<br />
&#8211;start<br />
my third file
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/05/splitting-files-using-visual-basic-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sendkeys in Visual Basic Scripts</title>
		<link>http://techblog.byllemos.com/2008/02/sendkeys-in-visual-basic-scripts/</link>
		<comments>http://techblog.byllemos.com/2008/02/sendkeys-in-visual-basic-scripts/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 21:56:48 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[Sendkeys]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[WshShell]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=43</guid>
		<description><![CDATA[<p>Sendkeys can also be used from a Visual Basic Scripts, which means you can ex. build a vbs file, that can be used for starting up applications, or executing steps that you often have to do.</p>
<p>This is an example&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Sendkeys can also be used from a Visual Basic Scripts, which means you can ex. build a vbs file, that can be used for starting up applications, or executing steps that you often have to do.</p>
<p>This is an example on starting the Notepad and afterwards, as the first thing to do writing the word Hallo:<span id="more-43"></span></p>
<blockquote><p> set WshShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)<br />
WshShell.Run &#8220;notepad&#8221;</p>
<p>WScript.Sleep 100</p>
<p>WshShell.AppActivate &#8220;Notesblok&#8221;<br />
WshShell.SendKeys &#8220;Hallo&#8221;</p>
<p>Set WshShell = nothing</p></blockquote>
<p>Lets take a closer look on what the script actual do. The first step is to initiate the object:</p>
<p>set WshShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)</p>
<p>when the object is initiate, the Notepad application is being startet:</p>
<blockquote><p>WshShell.Run &#8220;notepad&#8221;</p></blockquote>
<p>To be sure that notepad is up and running, there has to be a kind of wait state before continuing. This is done be telling the script to Sleep x milliseconds:</p>
<blockquote><p>WScript.Sleep 100</p></blockquote>
<p>Now the Notepad application has to be activated:</p>
<blockquote><p>WshShell.AppActivate &#8220;Notesblok&#8221;</p></blockquote>
<p>Once Notepad has been activated, it is ready to receive keys. Which now can be send with the sendkeys command:</p>
<blockquote><p>WshShell.SendKeys &#8220;Hallo&#8221;</p></blockquote>
<p>Finally you have to clean up after you &#8211; which means, to stop / close the WshShell you have to set it to nothing.</p>
<blockquote><p>Set WshShell = nothing</p></blockquote>
<p>Thats it &#8211; now you have written the Visual Basic Script &#8211; and all you have to do is save it as a vbs file, or incorporate it into a web page using th vbscript tags.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/sendkeys-in-visual-basic-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zip files in a script</title>
		<link>http://techblog.byllemos.com/2006/05/zip-files-in-a-script/</link>
		<comments>http://techblog.byllemos.com/2006/05/zip-files-in-a-script/#comments</comments>
		<pubDate>Wed, 03 May 2006 22:46:05 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[DOS]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[AT]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Zip]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=44</guid>
		<description><![CDATA[<p>If you have an application running, which creates a lot of log files &#8211; it would be neat to have simple functionality to zip those files. This is possible, just using dos scripts and the AT functionality.</p>
<p>First the script&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>If you have an application running, which creates a lot of log files &#8211; it would be neat to have simple functionality to zip those files. This is possible, just using dos scripts and the AT functionality.</p>
<p>First the script – it could look something like this:</p>
<p><span id="more-44"></span></p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">FindDate ----------------------------------------------------
for /f &quot;tokens=<span style="">1</span>-<span style="">4</span> delims=/.- &quot; %%A in <span class="br0">&#40;</span>'date /t'<span class="br0">&#41;</span> do <span class="br0">&#40;</span>
    set DD=%%A&amp;set MM=%%B&amp;set YYYY=%%C&amp;set Junk=%%D&amp;goto End<span class="br0">&#41;</span>
&nbsp;
:Parse --------------------------------------------------------------
echo Date: YYYY=%YYYY% MM=%MM% DD=%DD% JUNK=%Junk%
&nbsp;
:End ----------------------------------------------------------------
move c:\log\*.log c:\log\*.bck
c:\tools\zip.exe -m c:\log\Log%YYYY%-%MM%-%DD%.zip c:\log\*.bck</div></pre><!--END_DEVFMTCODE--><br />
</p>
<p>Lets take a closer look.</p>
<p>First we get today&#8217;s date by getting date and splitting into the peaces YYYY, MM, DD, JUNK, where JUNK is seconds, milliseconds and so on.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">
for /f &quot;tokens=1-4 delims=/.- &quot; %%A in <span class="br0">&#40;</span>'date /t'<span class="br0">&#41;</span> do <span class="br0">&#40;</span>
set DD=%%A&amp;amp;set MM=%%B&amp;amp;set YYYY=%%C&amp;amp;set Junk=%%D&amp;amp;goto End<span class="br0">&#41;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Notice – the setting of DD, MM and so on, differs from system to system. The above line works for a Windows 2003, where as the following line would work for a Windows 2000:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">set Junk=%%A&amp;amp;set DD=%%B&amp;amp;set MM=%%C&amp;amp;set YYYY=%%D&amp;amp;goto End<span class="br0">&#41;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Next we moves the files, this is to make sure that no application is writing to it.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">move c:\log\*.log c:\log\*.bck</div></pre><!--END_DEVFMTCODE--></p>
<p>and finaly the files are being zipped, using a dos version of zip.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">c:\tools\zip.exe -m c:\log\backup\Log%YYYY%-%MM%-%DD%.zip c:\log\*.bck</div></pre><!--END_DEVFMTCODE--></p>
<p>Now you have build the script, and can save into a file called backup.cmd (the extension could also be bat).</p>
<p>The next thing to do, is getting the script scheduled. In this way we don&#8217;t have to execute it manually every day. To do this we are using the AT command.</p>
<p>In a DOS prompt write:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title=""><div class="devcodeoverflow">AT 04:00 /every:M,T,W,TH,F,S,SU c:\tools\backup.cmd</div></pre><!--END_DEVFMTCODE--></p>
<p>Which means, that the script backup.cmd will be execute every day at 04:00. If you want to stop the scheduled job, simply perform an AT without parameters to get the ID and then afterwards make a AT ID /DELETE.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2006/05/zip-files-in-a-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

