Copy and rename a file

  • Hi,

    I would like to copy a flat file from one location to another and rename it. Can i do it in a single step coz I need to execute it as a daily job. does xcopy support this.

    Thanks in advance.

    Madduri

  • try "copy c:\myfolder\myfile.txt d:\yourfolder\yourfile.txt".

  • Thank you for your reply. I did it using ssis.

    Thanks, Madduri

  • SSIS might be expensive. Here is the simple way; create job and write following T-SQL command:

    xp_cmdshell "copy c:\myfolder\myfile.txt d:\yourfolder\yourfile.txt"

    ---------------------------------------------------
    "Thare are only 10 types of people in the world:
    Those who understand binary, and those who don't."

  • You can use CmdExec method (Using operating system command) also to run the command.

    To Use the extended stored procedure xp_cmdShell, it needs to be enabled. By default it is disabled due to security concerns.

    The Job Step will be some thing like this:

    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'copy file',

    @step_id=1,

    @cmdexec_success_code=0,

    @on_success_action=1,

    @on_success_step_id=0,

    @on_fail_action=2,

    @on_fail_step_id=0,

    @retry_attempts=0,

    @retry_interval=0,

    @os_run_priority=0,

    @subsystem=N'CmdExec',

    @command=N'ccopy c:\myfolder\myfile.txt d:\yourfolder\yourfile.txt',

    @flags=0

    Cheers,
    Prithiviraj Kulasingham

    http://preethiviraj.blogspot.com/

  • How did you do it using SISS? I have been trying to figure this out and I am fine with the fact that it might be expensive, I am trying to do this with a very small data set.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply