How to Clear Archive & Read-only flags on Files in Windows in Bulk
I ran into an issue where I had to move files from one system to another and was running into issues because files had been set as read-only, had the archive flag set, or both. It was causing the system to skip files which wasn’t acceptable. Normally you could just use Windows to clear it in bulk, but that could potentially mess up file permissions. I needed a way to automatically just clear all flags but respect permissions.
I did some searching and didn’t find a utility that would do the job and most of the solutions I found required Powershell which wasn’t available on the system I was on. I ended up writing a quick console application in C# to do the trick. I’ve made it free and open sourced it in case anyone wants to use it.
If you need just the app, you can find the release build here with instructions. The app also prompts for input to make things a bit easier to use. There’s no install, no tracking or metrics, or anything else related to privacy concerns in this app. It’s a simple throwaway utility to get the job done and move on.
https://github.com/gregvarghese/clearflags/releases/tag/1.0.0
If you want to see the source code, that is available here:
https://github.com/gregvarghese/clearflags/
Please note that I did this in about 10 minutes for my own use so error handling is pretty much non-existent. I mention this because I did run into one issue where Windows was somehow seeing a folder with files in it as a file and it couldn’t be deleted or renamed and the utility couldn’t get past it until it was resolved. I didn’t spend much time debugging and just used my Mac to rename the folder and Windows was able to recognize it after the change, so the utility was able to continue processing.
How to automatically install gulp dependencies
I created a website where I’m using gulp to create a minified version and had to switch to another computer. For whatever reason, gulp install wouldn’t install the dependencies automatically, even when using the “npm-install-missing” plugin.
Add this script to the beginning of your gulpfile.js before the requirements, and when you run gulp, it will install the dependencies automatically. Be aware you’ll need to rerun your gulp command after the script completes.
(function(){ var r=require; require=function (n){ try{ return r(n) } catch(e){ r('child_process').exec('npm i ' + n,function (err,body){ try{ console.log('Module "' +n + '"" not found, installing.\n' + body ) return r(n); } catch(e){ } }) } } console.log('""Please re-run gulp.\n' + body ) })()
Regex to parse date formats when unknown
I’m working on an app that will parse different file sources and aggregate it for a report. Of course, each format has a different date format and trying to parse it all has proved to be a pain. I wrote a regex that’ll parse out just about every datetime format I’ve run into that I am sharing in case someone else finds it useful. I’ve put it on a Github gist along with a sample of the various dates I’ve tested it against and confirmed to work. If you find a format not covered by the regex, post a comment and I’ll update the gist.
Just a note that I haven’t finished parsing the timestamp (e.g. 1997-07-16T19:20:30+01:00) format. The date portion does get extracted correctly so I left it in.
ASP.NET MVC Model Generator
In making the switch to ASP.NET MVC, I’ve moved away from using my old Data Access Layer that I’ve used for years and have opted to use Dapper as my ORM of choice in the quest for optimal performance. My DAL was actually pretty optimized for WinForms and WebForms (using straight SQL Queries and SQL parameters) but mapping it to models wasn’t something I had in mind when I created it. I’m finding Dapper takes some getting used too but it is still pretty fast. The downside is that writing the code for Models to wire it up is proving to be a little tedious.
To that effect, I wrote a little application that has helped me generate the models from a database dynamically. It’s in it’s infancy stages and something I cobbled together in less than 8 hours but it works. I’ll add more features too as time goes on if there’s enough interest or to satisfy my own needs. In the meantime, I’m open sourcing the project as it may help others and I’d love to see it become something grander if others are willing to contribute to it. There’s also some useful bits of code that others may find useful to reference like dynamically reading fields from a database, pluralization/singularization of words, amongst others.
You can find the repository on Github: https://github.com/gregvarghese/MVCModelGenerator