Question: While copying and renaming a file to a dynamic location through File System Task using variable throws an error
Error: Failed to lock variable "c:\test\test_200904202009.txt" for read access with error 0xC0010001 "The variable cannot be found. This occurs when an attempt is made to retrieve a variable from the Variables collection on a container during execution of the package, and the variable is not there. The variable name may have changed or the variable is not being created.".
OR
How to copy and rename a file to a dynamic location using SSIS?
Solution:
I will move and rename a file "test.txt" from c:\ to c:\backup with new name appended with date.
1) Create three variables
Src_File = c:\test.txt
Dest_File = test
Dest_Dir = c:\backup
2) In connection Manager create a File Connection with name as DestinationConn
3) In Expression property of DestinationConn use ConnectionString and provide following expression
@[Dest_Dir] + "\\" + @[Dest_File] + "_" + (DT_WSTR,4)DatePart("yyyy", GetDate()) + RIGHT("0" + (DT_WSTR,2)DatePart("mm", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("dd", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("hh", GetDate()), 2) + RIGHT("0" + (DT_WSTR,2)DatePart("mi", GetDate()), 2) + ".txt"
this will set the destination path and new name for the file
4) Create a File System task and configure like :
thats cool....
ReplyDeleteIm getting following error:-
ReplyDeleteThe error is thrown by Connections collection when the specific connection element is not found
hi
ReplyDeleteneed help
In above expression we get getdate as file name . But in my case i need one day previous date from Tusday to Friday and on Monday 3 days previous date .
Could you plz help .
Thanks
This is Good One
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteThanks is was exactly what I needed
ReplyDeleteThanks is was exactly what I needed too
ReplyDeleteThnxx a lottt..!!
ReplyDeleteVery good it works
ReplyDeleteThank you so much!!!!!!!! This is what exactly I am looking for and it worked for me. :)
ReplyDeletePleasure
ReplyDeleteI've been trying to do similar but with several files. What's the set up on the ForEach Loop Container? Can it be done?
ReplyDeleteThank you!!! I've just lost 1/2 day trying to do the same thing in a wrong way!
ReplyDeleteHi , I have got a error stating destination connection manager DestinationConn has an invalid usage type "Folder Exists" KINDLY HELP ME
ReplyDeleteWell done... thank you!
ReplyDeleteThis is awesome. thanks!
ReplyDeleteThanks alot man!!!
ReplyDeleteproblems copying or renaming files
ReplyDeletewebsite:LongPathTool.com - unlock and delete path too long files
When you are having problems with deleting, copying or renaming files
on your computer, you should get an effective tool. You can find
Windows tool to delete or copy folders and files with errors such as
path too long or the filename too long. Basically search the file and
then press the button to delete or copy it. Path too long application
solves problems with the capacity to delete or copy files and folders
with the long paths in Explorer. At times, errors are created by
software programs, virus, adware and more.
Works like a charm, thanks a lot!
ReplyDeleteYou are really kind genius
ReplyDeleteI like this trick. This trick is good for users who love to play with technical ways. However, I have used “Long Path Tool” in this situation and it helped me easily and quickly. So this tool is best for those members who don't love to play with technical skills.
ReplyDeleteThis is a great post. Very simple to follow and it works! Love it!
ReplyDeleteCan we move a file into a folder then rename it appending date with the file name?
ReplyDeleteGood One Man.Carry on with your great work
ReplyDeleteFinally! An example of a rename and copy that works! Thank you.
ReplyDeleteperfect, thanks !
ReplyDeleteWorked like a charm!!! Thanks
ReplyDeleteYes this method really works on my blog. I am thankful to your article and suggesting also to other friends to have a look on it.
ReplyDeleteI cant down load this package, what do i have to do?
ReplyDeleteSuper helpful...thanks
ReplyDeleteThank you very much for this great tool. It work very well when you run it in Visual Studio.
ReplyDeleteUnfortunately, when I try to run teh package from a SQL Job, I got the following error :
Error Code: 0xC0012024 Source: TimeStamp & Backup Description: The task "TimeStamp & Backup" cannot run on installed (64-bit) of Integration Services. It requires Standard Edition (64-bit) or higher. DTExec: The package execution returned DTSER_FAILURE
Any idea why ? Thank you again for your work.
Sweet! Thanks. I was struggling with trying to set expressions on the File System Task and not the Connection Manager.
ReplyDeleteProblem: This performs a move & rename not a copy & rename .....
ReplyDeleteSolution: change operation to copy file
Hello..
ReplyDeleteWe have same situation.
Long Path Tool helped me. http://PathTooDeep.com
You can visit and check out. Thank You!
Good Job! Exactly what I'm looking for. Thank you!
ReplyDeleteThanks a lot, it solved a lot of issues!
ReplyDeleteWalter
Thanks for posting your posting, it really helped me to solve my requirement.
ReplyDeleteBhandary
Thanks,.... that did the trick!
ReplyDeleteHow can I get it to copy and rename. When I try this it is moving and renaming.
ReplyDeleteI use a software for this" Long Path Too"l and it really works for deleting copying and renaming files or folder.
ReplyDeleteVery Nice! Excellent post and precisely what I needed without a lot of grief or endless searching on the WWW. Thank You Sir!
ReplyDeleteBob
Just what I needed. Thanks!
ReplyDeleteHi Buddy,
ReplyDeleteIt executes only once , if we want to rerun the task its not executing ,is there any alternative to process it.
Hi
ReplyDeleteI suggest to try "Long Path Tool" program .
before I have problem cannot copy file because file name too long. and after I found long
path tool and now my problem solved
Thanks
Patrick
the maximum ... thanks
ReplyDeleteIt is usefull software for copy, delete, long path files.
ReplyDeleteTry "Long Path Tool" program.
I would recommend in this case to try program Long Path Tool
ReplyDeletevery helpful. thank you
ReplyDeletei need to do this for some files is possible ?
ReplyDeleteExactly what I needed! Perfect solution for single file archiving and date-stamping, when looping through a directory is NOT required! Thanks Rahul - you're a stud brother!
ReplyDeletemany many thx Rahul
ReplyDeleteexactly what I was looking for and documented in a way that I was able to use it without any experience with SSIS.
I would recommend you to try Long Path Tool program to fix this problem
ReplyDeleteWorked great for me. Thanks!
ReplyDeleteHello There,
ReplyDeleteWhat you’re saying is absolutely correct Copy/Rename a file using File System Task in SSIS, but this isn’t the exact situation everywhere. Where most smart folk work on a project - why can’t you do this the Boss asks :).
I decided I had better get all the spec's for my dell latitude d600 and post them to see what linix os I can use. I use my laptop for personal and business use for my Ham Radio events, such as skywarn and emergency communications.
But great job man, do keep posted with the new updates.
Cheers,
Preethi.