FileBots transform files quickly, on-the-fly from the comfort of your very own Windows Explorer.
Occasionally, I’ll need to transform text files that I’m working. This will usually happen when I’m porting over old, ASP-based applications to ASP.NET or converting from VB.NET to C#—that sort of thing.
Recently, I was converting over an old site that had HTML in all uppercase. This used to be the standard. But, as you know, XHTML requires everything to be in lower case.
To solve the problem, I really didn’t need anything fancy. I wasn’t trying to create anything perfect. No need to employ DOMs or YACC and such. I just wanted to crank out something real quick that would convert the majority of the HTML as I needed it. There’s probably even a plugin to VS for this but I didn’t look. If you find one, let me know. VS doesn’t do this for me that I could find.
So, to make my life easier with as little effort as possible, I created a console app (.EXE) that takes the first argument as the name of the file. In the console application, I just load the file, do the processing and then save the file with a ".actionTaken" extension. Done! I call these little applications FileBots.
Let’s look at at a FileBot a little closer. Here’s the Main() routine from a recent FileBot that I created that lowercases the elements and attributes in an HTML file:
Example 1: C# Main for a FileBot
Pretty straight forward, yes?
"Yeah, but you just created a console application! How is that going to make things easier for me?" you might say. Well, here’s the sweet part about Windows. Drop this .EXE in to your SendTo folder located here:
C:\Documents and Settings\LoginName\SendTo
Now, when you right-click on a file, you’ll see that the .EXE shows up in the Send To menu as a valid option. When you choose the program from the menu, the Windows explorer executes the application with– you guessed it–the file name as the first argument!
In the example above, you’ll notice that in just one line of code, I read the file, process it and write it back down. I don’t even bother with error handling. No need.
In the code that follows, I start notepad.exe and pass the output filename to it. You don’t have to open the file in notepad. You can do whatever you want including not doing anything.
This is really useful I think. Take it one step further. You can select the previous output filename and then send it to another FileBot until you get the final results you’re looking for. This is similar to the UNIX and MS-DOS pipe without having to go to a command console and chain them together.
The key is, when developing, don’t try to over engineer your scaffolding code. Be smart. Use the OS and the development environments to help you move quickly. And, I sure as heck had a lot more fun creating the above than searching and replacing HTML in hundreds of files. Take a second every now and then to add a tool to your chest. It pays off in the long run.
Now, go make some FileBots!