Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 How to move files by using SQL ?

Author  Topic 

Mathias
Posting Yak Master

119 Posts

Posted - 2004-11-03 : 07:15:14
I get many uploads coming into one single directory. I plan to create a table where the first field would containt the source_destination another with the Final_destination.
Example
c:\tempdata\*.txt as source_destination
c:\tempdata\d1\ as final_destination

Is there any way to automate it? I would like to kill the first file after the copy. The table is dynamic (I get new request every week).
Thanks, Paul

Soulweaver
Starting Member

18 Posts

Posted - 2004-11-03 : 07:26:51
the only way i'm aware of of doing file management type stuff in SQL server is to use the XP_CMDSHELL stored procedure.

you can use a normal dos 'MOVE' command to move the file, for example

exec master..xp_cmdshell "move c:\tempdata\*.txt c:\tempdata\d1"

regards
Tiaan

ps. you need quite a bit of rights to run XP_CMDSHELL, however, if you need it, i can help you setup the SQLAGENT proxy account.

pps. XP_CMDSHELL is dangerous, you can break many many things with it.

-----------------------
Black Holes exist where God divided by Zero
-----------------------
Go to Top of Page

Soulweaver
Starting Member

18 Posts

Posted - 2004-11-03 : 07:29:58
more info

you can build up the exec string from your table and then exec it :

eg :

set @sqlstring = @sqlstring + @itempath + '\*' + @itemextension + '" '+ @diroptions

run with

exec (@sqlstring)


-----------------------
Black Holes exist where God divided by Zero
-----------------------
Go to Top of Page
   

- Advertisement -