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.
Andre Guerreiro Neto