Hi,
see the last 3 line. It will work. May be you have to delete one '.' :hehe:
SET @cmd = 'bcp ' + @dbname + '.' + @tablename + ' ' + @direction + ' ' + @filepath + ' -T -c'
PRINT @cmd
--To run the bcp using extended stored procedure.
EXEC master..xp_cmdshell @cmd
---