title: SSIS - Deleting Files in For Each Loop errors due to locked variable
body: <p>I have an SSIS package that looks in a folder, loops through each file inside, imports file to SQL Server, executes a SQL task, then needs to delete the file, then loop through next one.  The import and looping works without the delete file step (File System Task), but the delete file errors with the message "Failed to lock variable.  The variable cannot be found."  The variable in question is the variable I created for "Current File".  It's being used by the first part of the For Each Loop container to look up the current file and import it successfully.  What I think is happening, importing the file locks the variable.  Then when it's going to delete the file based on the variable, it can't access the variable because it is locked, so it fails.  Any idea how to allow it to import the "Current File" based on the "Current File variable", then delete it based on that same variable, then loop through the rest of files?  Taking the delete file control out of the For Each Loop is not an option, because I need to delete each file after it imports - if I do a delete after all import, I might delete files in the directory which got there after I ran the import, so I'd be deleting non-imported files, I think.  Thanks for any help!</p>