Putting SQL Server databases into individual folders We have a Dev server where we are trying out some automated partitioning scripts.  

The folder is getting quite large in terms of number of files.

Is it possible to automatically have SQL Server use a sub folder for all files pertaining to each one of the databases using the database name as a sub-folder name?
Now this should really be a feature, I tried to find it on Microsoft connect but did not if anyone has a way to do this via database properties I for one would be very happy. 

But as it stands this is not possible except by changing the default database location registry setting either in the server properties or like this.

USE [master]
GO
— Change default location for data files
EXEC   xp_instance_regwrite
   N'HKEY_LOCAL_MACHINE',
   N'Software\Microsoft\MSSQLServer\MSSQLServer',
   N'DefaultData',
   REG_SZ,
   N'C:\MSSQL\Data'
GO
— Change default location for log files
EXEC   xp_instance_regwrite
   N'HKEY_LOCAL_MACHINE',
   N'Software\Microsoft\MSSQLServer\MSSQLServer',
   N'DefaultLog',
   REG_SZ,
   N'C:\MSSQL\Logs'
GO


But if you have multiple databases on the server you would have to remember to change this before adding a file to each of them. 

There is also the possibility to to this dynamically, you could create a stored procedure that you call with a database name that will read the current path for the mdf file and add a new file to the same path so to borrow a bit from stackexchange

create procedure USP_ADDFILE 

@database sysname,
@logicalname sysname,
@filename sysname,
@filegroup sysname,
@size int
AS
if @database is NULL return 
if @filename is null return
if @filegroup is null set @filegroup = 'Default'
if @size is null return
Declare @Path nvarchar(max)
Declare @Sql nvarchar(max)


select @Path = (select LEFT(physical_name
                   ,LEN(physical_name)-CHARINDEX('\',REVERSE(physical_name))+1)
    FROM sys.master_files mf  
    INNER JOIN sys.[databases] d  
    ON mf.[database_id] = d.[database_id]  
    WHERE d.[name] = @database AND type = 0)

Set @Sql = 'Alter Database '+ QuoteName( @database )+'
    Add File( Name = '''+ @filename +'''
            , SIZE = '+ CAST (@size as nvarchar(10)) +'GB
            , FileName = ''' +  @Path+@filename+'.NDF''' 
            + ') To FileGroup '+QuoteName(@filegroup)  +''
exec ( @Sql )