Error, does not compute – Input validation

Input validation via a function and regex

In past posts, some of the functions have included param / parameter to test or set various variables. This is a very good (and likely just a very correct) way of scripting, you should learn to do it. I should learn to do it more too but I’m too concerned about making user input correct AND easy for the user to deal with AND as flexible as possible. I do not want to be making multiple functions to make sure input data is correct.

So I made this simple function

function FNvalid_entry($msg,$regX){
	while (!$val_ent){
		$val_ent = read-host $msg
		if ([regex]::ismatch($val_ent,$regX)){
			break
		}else{
			write-host -fore yellow "Bad format"
			remove-variable val_ent
		}
	}
return $val_ent
}

Continue reading “Error, does not compute – Input validation”

Locked up tighter than Fort Knox – Test for file locks

A function to test for file locks quickly and easily.

On occasion you may have a need to update a central file from multiple locations or scripts. Most of the time it presents little issue however constant small writes may lead to multiple systems, scripts, workflows etc attempting to update a file at the same time, which could result in lost data. Some may shout out saying this is a design issue (I guess it is), though sometimes the scope of a script changes suddenly and no time or budget is given to adapt to the new situation.

This is where a small function to test if a file is in use can be very handy… Continue reading “Locked up tighter than Fort Knox – Test for file locks”