<?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>analog feelings, digital world &#187; SyncToy</title>
	<atom:link href="http://notonlyzeroesandones.site40.net/tag/synctoy/feed/" rel="self" type="application/rss+xml" />
	<link>http://notonlyzeroesandones.site40.net</link>
	<description>code is the modern poetry ;)</description>
	<lastBuildDate>Mon, 05 Oct 2009 22:06:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>What have I learned thanks to SyncToy?</title>
		<link>http://notonlyzeroesandones.site40.net/2009/04/14/what-have-i-learned-thanks-to-synctoy/</link>
		<comments>http://notonlyzeroesandones.site40.net/2009/04/14/what-have-i-learned-thanks-to-synctoy/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 11:58:29 +0000</pubDate>
		<dc:creator>Maciek Talaska</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[my projects]]></category>
		<category><![CDATA[c# 3.0]]></category>
		<category><![CDATA[SyncToy]]></category>
		<category><![CDATA[System.IO]]></category>

		<guid isPermaLink="false">http://notonlyzeroesandones.site40.net/2009/04/14/what-have-i-learned-thanks-to-synctoy/</guid>
		<description><![CDATA[If you haven’t used SyncToy – it is high time to check what it can do for you. In short: this is a great synchronization tool, originally written to help photographers (or amateur photographers) synchronize between their studio storage devices (computers) and mobile data banks. I have started using SyncToy to synchronize content on two [...]]]></description>
			<content:encoded><![CDATA[<p align="justify">If you haven’t used SyncToy – it is high time to check what it can do for you. In short: this is a great synchronization tool, originally written to help photographers (or amateur photographers) synchronize between their studio storage devices (computers) and mobile data banks. I have started using SyncToy to synchronize content on two of my disk (I want one of them to be the exact copy of the other one). The disk are quite big (about 200GBs) so doing a “preview” of changes takes a while. Yesterday although, SyncToy was unable to finish preparing preview, because there were some files / folders with invalid chars in their names. The <a href="http://social.microsoft.com/forums/en-US/synctoy/thread/7c9057ef-c4c7-410c-a3c6-50ff0105988d/">problem is known</a> to both sides: SyncToy users and Microsoft’s developers, but suggested solutions didn’t help me at all (I didn’t know what exact file or directory is causing problems to SyncToy).</p>
<p align="justify">So&#8230; I make a quick look at what can I find inside System.IO, and <a href="http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidpathchars.aspx">Path.GetInvalidPathChars()</a> and <a href="http://msdn.microsoft.com/en-us/library/system.io.path.getinvalidfilenamechars.aspx">Path.GetInvalidFileNameChars()</a> – it seemed that those functions will help me find those files and directories that contains illegal characters. Boy&#8230; I was wrong ;)</p>
<p align="justify">At the beginning I wrote a very simple program (C#) that recursively traversed through all <a href="http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo(VS.71).aspx">FileSystemInfo</a> objects (using <a href="http://msdn.microsoft.com/en-us/library/s7xk2b58.aspx">GetDirectories</a>() and <a href="http://msdn.microsoft.com/en-us/library/ms143327.aspx">GetFiles()</a> methods) present in a given directory. The problem was, that when GetFiles() method was invoked inside a directory that contained files with illegal characters – program crashed (“Illegal Argument Exception”). I couldn’t understand it. I know what was the directory that caused problem and I easily found a file that was a cause of all this mess. The file name contained a pipe “|” character that is not allowed (at least on Microsoft’s systems). </p>
<p align="justify">I wondered how should I change my small utility to make it able to find all illegal files and generate a cute report at the end instead of crashing. I could see the file using Total Commander, Windows Explorer and even dir command executed within cmd.exe. I could – however – copy the file, rename it (tried bazylion of different approaches to achieve this task – using <a href="http://msdn.microsoft.com/en-us/library/aa365247.aspx">Universal Naming Convention</a> didn’t help a bit). I decided to rewrite main part of my utility and to use System.Diagnostics.Process and output of “DIR /A-D /B” for files and “DIR /A:D /B” for directories. My idea was to not checking the names of FileSystemInfo objects that I can get without problems using GetFiles and GetDirectories methods. I assumed (and I hope that it is assumption is correct) that if information about a file or directory can be get, than there is no problem with this object. So I decided that my code should now look more like this:</p>
<pre class="c#" name="code">try
{
    FileInfo[] files = root.GetFiles();
}
catch (System.UnauthorizedAccessException)
{
}
catch
{
    GetSystemEntries(root, EntryType.File);
}</pre>
<p align="justify">In the function that traverses through all the object there is another similar block of code that does similar task but for directories. I wasn’t sure if this approach is ok – exception catching influences performance, but it didn’t take more time than SyncToy to look through all my drive (so I assume that the performance is acceptable). GetSystemEntries is a function written by me, that invokes dir command in specified directory looking for files or directories, and analyzes output (checks if there are any invalid characters in file or directory name).</p>
<p align="justify">Yup, one problem resolved. But what about the file? As far as I remember, it was created by a browser (saving page) and it’s name comes from the title of the page, which was divided in sections using pipes. The funny thing (for me) is that I can not understand how OS may actually allow anyone to create a file with invalid characters in name (I suppose this file was created by Mozilla Firefox 3.0x). I have spent a lot more time looking for a solution how to delete the file, rename it, or do whatever to make it a file with a valid name. Back in the old dos-command-prompt days I used several times a great tool by Norton – diskedit.com – it was very powerful disk editor, that saved me a couple of times. But&#8230; although I found some similar tools, I was a bit too afraid to use them. NTFS is much more complicated than good-old FAT, and I really didn’t want to lose all my data. I rebooted to Ubuntu, and tried renaming. It worked. Then I tried to remove the file. No problems. So&#8230; thank you <a href="http://www.canonical.com/">Cannonical</a> :)</p>
<p align="justify"><a href="http://notonlyzeroesandones.site40.net/my-projects/badfilename/">App sources are available on this blog.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://notonlyzeroesandones.site40.net/2009/04/14/what-have-i-learned-thanks-to-synctoy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->
