You could also use a CLR assembly with code to do that but it depends on the environment and the security of the server. It's a bad idea to leave 'xp_cmdshell' enabled in a production environment.
Why not use a programming language to do what you need? I don't think T-SQL is the right tool to use here but I could be wrong.
Best regards,
Best regards,
Andre Guerreiro Neto
Database Analyst
http://www.softplan.com.br
MCITPx1/MCTSx2/MCSE/MCSA