August 24, 2010 at 2:50 pm
Hello Everyone
I am working on a package that I have a file copy process setup.
I have this working perfectly. I never thought about this before I began, but the file creation date will be changing everyday to the current date.
I am using an XML config file to give the admin person a way to adjust the time range. But they cannot go in a modify this file daily, just to input the current date. The files that I want to copy have a date time creation date, My code is copying the correct files if I use something like 4/10/2008 1:57 PM However, I want to compare Only the time, and not the date of the file.
How can I accomplish this? I am using C# as my script code language.
Thank you in advance
Andrew SQLDBA
August 24, 2010 at 3:07 pm
Sounds like a good use of the "For-Each container". This can be set for files in a folder (even with a mask), and sets a variable to the file name. Then use that variable in a File System Task to copy the file.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 24, 2010 at 3:12 pm
Will not work
The file names change daily.
I want to copy only the files that are created between a certain time of day. Say between 1:30 PM and 2:00 PM
No matter what the file name is.
I have the code working that will copy the files, as long as I modify the XML config file everyday with the new date of the current date. I want to copy the file that contain any date, but within a certain time. Do not care about the date created.
Thanks
Andrew SQLDBA
August 24, 2010 at 10:31 pm
Andrew,
This is what I understand,
You have a file name such as MM\DD\YYYY_TIMESTAMP
In such case inside a FOREACH container you will have to implement a Script Task
A collection will store all relevant strings of TIMESTAMP....you can use the String functions provided by .NET to achieve the same.
Raunak J
August 25, 2010 at 12:33 am
AndrewSQLDBA (8/24/2010)
Will not workThe file names change daily.
I want to copy only the files that are created between a certain time of day. Say between 1:30 PM and 2:00 PM
No matter what the file name is.
I have the code working that will copy the files, as long as I modify the XML config file everyday with the new date of the current date. I want to copy the file that contain any date, but within a certain time. Do not care about the date created.
Thanks
Andrew SQLDBA
So you have a folder full of files created at various times and your requirement is that every time your package runs, every file created between time x and time y, regardless of date, gets copied somewhere?
Doesn't that mean that files already copied (because they were created before 'today') will be copied again?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 25, 2010 at 8:37 am
Hey Phil
Very close. There is another package that fires off at midnight that deletes all files, after copying all of them to an archive directory. This is only for a group of SQL developers that need these files for some development. They are actually SQL trance files that are being generated on a prod sql box.
I am getting the file times now, I just do not know how I can compare that time with what I have listed in a variable. C# cannot compare text nor datetime values.
Any suggestions? I have thought about converting them to minutes or seconds that would be an integer value, that will compare.
Thanks
Andrew SQLDBA
August 25, 2010 at 8:43 am
SQL trance files eh? Whatever would Freud say? 🙂
See my reply post to another thread of yours regarding time comparisons - no trouble really.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 25, 2010 at 9:10 am
Hey Phil
I think that I may have mis-typed.
I am using two variables minTime and maxTime
minTime = 1:55:00 PM
maxTime = 1:57:00 PM
I am using the time the file was created to determine if that time falls between the minTime and MaxTime. And if so, that file gets flagged to copy.
I can do this fine if I use the entire date and time. But I am having some difficulty in using only the time for some reason. Would I place the entire date and time in my package variable?
Thanks
Andrew SQLDBA
August 25, 2010 at 9:22 am
OK, maybe I understand your problem. You want to know how to get just the time bit into a datetime variable?
You can't do that, but you could put a dummy datetime in there, say 1/1/2000 11:15 or whatever, and then just replace the dummy date part in code, leaving the time in place.
Then you can do your comparisons.
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
August 25, 2010 at 9:40 am
Phil
That is just what I have done, I am more of an ASP.NET developer. I am using that so that I can place breakpoints and more quickly see the values in the variables.
I am working on that code now, I think that I may have it close. I have changed the package variable data types to string, instead of datetime, and it seems to be easier to be able to convert them and pull off the time only, and then convert it back to datetime.
Let me do some more testing, and I will let you know.
Thanks for your help
Andrew SQLDBA
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply