Link to home
Start Free TrialLog in
Avatar of newbieal
newbiealFlag for United States of America

asked on

SQL Server 2005 job: move and copy file in DOS

How does one add a move and copy file dos command to a sql server job?  And how does it record the date/time of the copy and move of the file?
Avatar of chapmandew
chapmandew
Flag of United States of America image

I would think that you would have to do it either in SSIS as an Execute Process task, or using xp_cmdshell as a job step in the job.  As for the 2nd question, I am not sure what you maen.
Avatar of newbieal

ASKER

I would need an actual example of the actual DOS command.  I guess there are two involved, copy and move.  

Also, to clarify my second question: I want there to be a date and time stamp for when the task of copying and moving a file in DOS was accomplished
SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Due to security measures on our system we are not allowed to use xp_cmdshell.  Is there any other way to do this?
If you are using 2005 you could write some CLR procedures that move the file for you.  
could you give an example for clr procedure for my case?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If we disregard the fact that I need to do this via sql server, how would the commands look if I would just do it in DOS directly?
copy c:\moveme.txt c:\tracefiles\moveme.txt

or

move c:\moveme.txt c:\tracefiles\moveme.txt
what about the date stamp?
I should clarify when we move then rename the file to include the date when the file was copied/moved, so:


move c:\moveme.txt c:\tracefiles\moveme02212008.txt
Is it OK to write the date out to a different file?
not sure what you mean, can you give an example?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I get this error:

syntax of the command is incorrect
post your script
I did this in dos using your command above, there is nothing else I can provide.
did you swap out the file names for a file on your c drive?  Did you make sure you typed out all the little ~ and % characters correctly?
yes, and I will double check - this works on your computer?
after double-checking it worked. thanks!!