[UTIL] Right-Click "Touch File" - Recycle that web app - Jon Galloway

[UTIL] Right-Click "Touch File" - Recycle that web app

We've been using external config files to manage separate dev.config / qa.config / prod.config settings for a while and it's worked pretty well. Pretty code sample here. The one difference here is that changes to the referenced external config files don't get picked up right away as web.config edits do, so we're always editing web.config to add / remove whitespace just so the ASP.NET application cache is invalidated and the app reloads, causing it to pick up the new config values.

What would be better is something like the unix touch command... from the right click menu...

I googled like mad and came up empty, so I decided to DoIt myself. While I was at it, I added a right click Backup function - it makes a copy of a file with .bak on the end - project.dll -> project.dll.bak, for instance.

Sadly, nothing fancy here - shell calls to the cmd copy function (you gotta edit it to command.exe if you're on Win98 / ME). The Touch command copies the file back over itself, giving it a new timestamp. The copy function checks for and prevents this, but it does support file concatenation so we just concatenate a nul. /b specifies binary mode which strips the null character, and /y says yes so you don't have to. And the best part - I'm really proud of this - it flashes the console window up on the screen to remind you of our glorious DOS heritage. Also because I couldn't figure out how to hide that. The Touch command is only added to config files, while the Backup command is added to all files (should I make Touch apply to all file types?). You can select multiple files and select Backup and it will get them all.

I've tested these a good amount, both locally and on mapped drives, but please blame Microsoft and not me if this eats your production web.config files. Let me know, though, so I can update this.

Download zipped reg file here

Or you can just save this text to a reg file and merge it:

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\VisualStudio.config.7.1\shell\Touch\command]
@="cmd.exe /c copy %1+nul %1 /by"
[HKEY_CLASSES_ROOT\*\shell\Backup\command]
@="cmd.exe /c copy %L %L.bak /by"
[HKEY_CLASSES_ROOT\configfile\shell\Touch\command]
@="cmd.exe /c copy %1+nul %1 /by"

Epilogue: Just after finishing my masterpiece (see above), I saw that Steve McMahon (Mr. vbAccelerator) has done this before: vbAccelerator Touch Utility. If you haven't checked his site out lately, give it a look. Nice site, great stuff. I like my solution better, though - not just because it kept me up until 2 (at which point the baby woke up), but because mine is simpler, there's no exe file to accidentally delete, it takes 1/30th the disk space, and because Steve makes me feel stupid and I frankly resent it.

Published Friday, February 20, 2004 12:38 AM by Jon Galloway
Filed under:

Comments

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

Justin, follow the link on the first line, to understand what this is for, i.e. not web.config files, *external* config files.

Friday, February 20, 2004 9:10 AM by Johnny Hall

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

BTW, I get "this file does not have a program associated with it for performing this action. Create an association in the Folder Options control panel."

Not sure what's up, and I haven't got the energy to search through the registry atm.

Friday, February 20, 2004 9:13 AM by Johnny Hall

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

Johnny -
I used the existing file associations set up by VS 2003 on install. If VS 2003 isn't installed on the computer you're using this on, you'd get that error. If that's the case for you, I can add those but I'll need to test them out a good bit to make sure they're not going to mess with the VS settings should it be installed later.
- Jon

Friday, February 20, 2004 10:47 AM by Jon Galloway

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

Justin-
Yep, what Johnny said. The cache dependency is only on web.config, not on referenced external files.
- Jon

Friday, February 20, 2004 10:48 AM by Jon Galloway

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

I've got VS 2003 on my machine. I get this error message with Backup too.

So, you can understand my confusion.

Friday, February 20, 2004 10:53 AM by Johnny Hall

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

I got off my arse, and checked the registry.

The "command" Data was empty. Don't know enough about .reg to know why but the file ^ above doesn't seem to work.

I've fixed it manually now.

Friday, February 20, 2004 10:58 AM by Johnny Hall

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

Johnny-
Weird. I just removed all the keys and reinstalled from the file I posted above and it worked for me. Sorry for the hassle.

If anyone else runs into this I'd be interested to hear about it. You might want to just copy the text above to a txt file, rename it to a .reg file, and merge it.
- Jon

Friday, February 20, 2004 12:07 PM by Jon Galloway

# re: [UTIL] Right-Click "Touch File" - Recycle that web app

Or you can get touch for windows. It is part of gnu coreutils package. Search for "touch gnuwin32".

Monday, July 28, 2008 8:59 AM by Arik