October 3, 2007 at 10:36 am
I'm using the Foreach Loop container to loop through a directory and move the files in that directory to a different directory. The directory that I'm moving from will have a new file created each hour and the newest file will be in use, so I don't want to move it. I can't seem to find a way in the task to exclude a file based on it's date created or date modified. Is that possible to do within the task or do I need to create a custom script? The files are named using the date along with the hour and minute it was created. Any help is appreciated.
Wendy Schuman
October 3, 2007 at 11:20 am
If by "in use", you mean the file will be currently open by another process, you will get an error when you try to move it anyway, just handle the error.
If you mean something may still need to open and write to that file, the easiest way will be to create a string variable, use an expression to build your file name.
Within the loop container add a task that does nothing (an empty script task will work).
Drag the connector from this task to your file system task.
Right-click on the connector and use your variable to compare to your file variable from the loop container and do not run the move task if the file name is the same.
October 4, 2007 at 2:18 pm
Thanks for your reply. Yesterday I was able to loop through the directory and move all of the files and it worked fine. Then I tried to do what you suggested by creating the variable in an empty task...but I never finished that part. Today when I try to run the package I'm getting an error that the file can't be found. So I created a new package with just the ForEach Loop and the File System task and am still getting the error. It's confusing because it says it can't find the file but it appears to be looking in the wrong directory. My ForEach Loop is specifying this folder: C:\Web Logs\LogFiles, but the error says it can't find the file in my Program Files folder. The error is:
Error: 0xC002F304 at File System Task, File System Task: An error occurred with the following error message: "Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\200705311303_www.testsite.com_7001.log'.".
The name of the file is correct. I am using the file name variable from the ForEachLoop as my source variable in my File System Task and my destination path is C:\Web Logs\LogFiles_Staging and is not a variable. I'm pretty sure I set everything up the same as I did yesterday so I'm very confused as to what the problem is. Do you know what could be causing this?
Wendy Schuman
October 5, 2007 at 5:26 am
Just, a guess, but try checking out the scope of the variable. It may not be available during the For/Each loop process.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply