Moving files from one direcory to another

  • Hi,

    Does anyone perhaps have a script that takes a file and puts it in a different directory and then renames the old file.

    IC

  • I dont have a script but the commands are as given below.

    move <<SOURCEpath>>\filename <<DESTINATIONPATH>>\filename

    rename <<SOURCEPATH>>\filename filename

    the first will move the file to the destination location adn the second will rename your file. You have to change the path alone.

    Cheers,
    Sugeshkumar Rajendran
    SQL Server MVP
    http://sugeshkr.blogspot.com

  • Hi,

    Agree with Sugesh. And if you are planning to do it from sql server, then use xp_cmdshell to execute the above commands.

    But you will require sysadmin fixed role to execute this command. Which is risky as far as security of your database is concerned.

    Thanks

    Sachin

  • I use stored procedures to move my files around with my SQL Servers.

    They look something like

    CREATE PROCEDURE [dbo].[msp_copy_Server_SQL_Full_Daily_Backups]

    AS

    DECLARE @command varchar(100)

    DECLARE @location varchar(30)

    DECLARE @destination varchar(41)

    DECLARE @switches varchar(6)

    DECLARE @day char(9)

    SET @day = DATENAME(Weekday, GETDATE())

    PRINT @day

    SET @location = '\\Server_Name\Folder\*.*'

    SET @destination = '\\Destination_Server_Name\Destination_Folder\'

    SET @switches = '/E/H/Y'

    SET @command = 'xcopy' + ' ' + @location + ' ' + @destination + @day +' ' + @switches

    EXEC master..xp_cmdshell @command

  • Hi all,

    Don't you have to detach database prior to moving files and then re-attach them back from new location ?

     

  • IF you are moving actual database files, that's true. However, if these are flat files, there's no such constraint.

  • You might want to check out the FileSystemObject and the File objects in VBScript.  There are lots of methods and properties that will give you more options.  And of course you can run the script in a job.

    Regards,
    Rubes

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

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