sql-server-log-file-path

A simple way to get the default SQL Server data and log path

For things like automated SQL Server build scripts (and probably many other reasons) finding the root data and log file paths is essential. Prior to SQL Server 2012 there were all sorts of options ranging from e.g. running sp_helpfile against the master database (which is not foolproof) or constructing a string to establish the right registry key to search (which can be a pain for named instance) and then running an undocumented extended stored procedure called xp_instance_regread to get this information.