loop through file name and detect invalid filename and move to another folder
Hi
My file name are of format
EAGLE_UODS_CAMEL_20120704401116_000001.csv
I need to loop thorugh set of file to check the naming standard and if it is not valid i need to move the file to another folder.
Can this be done in SSIS?
Any help is appreciated.
September 6th, 2012 12:03pm
Replied on a similar post this morning. Have a look
here. Couple of solutions available there; take your pick.http://btsbee.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
September 6th, 2012 12:09pm
use 2 loops
loop one will filter out the files and move the unwanted files to the to the right location (unwanted format files folder)
loop 2 will process the remainning files
1- loop one -- use a loop to loop files
2- use a script task to falg each file use scripts like
Dim strPathAndFileName As String = Dts.Variables("uVar_CurrentFileName").Value.ToString()
If File.Exists(strPathAndFileName) Then
'FileDate = File.GetLastWriteTime(strPathAndFileName)
'File.GetAttributes(strPathAndFileName).GetName()
strLen = Len(strPathAndFileName)
LastSlashPosition = strPathAndFileName.LastIndexOf("\")
strPointer = strLen - (LastSlashPosition + 1)
strFilePath = Left(strPathAndFileName, strLen - strPointer - 1)
strFileName = Right(strPathAndFileName, strPointer)
strLenFullFileName = Len(strFileName)
strLen = strFileName.IndexOf(".")
strFileExtension = Right(strFileName, (strLenFullFileName - strLen - 1))
strFileName = Left(strFileName, strLen)
this will give you the file name , folder, extension and etc... that you need in the same script task just check if your file name has the right format and set a FLAG to true or false
3- after the script you need one object "File system task "FSYS" the arrow in between the script and the FSYS must have the flag set in the Percedence Constart
and the setting must be like
Evaluation operation : Expression and constraint
Value : Success
Expression: @u_VarFlag == TURE Assuming TRUE means to redirect the file to the 'unwanted format files folder'
good luck
PLease note that they are other way that you can exclude the script task
and you MUST add your checking in the script task to check your format that you are looking for , i didn't add that part
Sincerely Nik -- Please kindly mark the post(s) that answered your question and/or vote for the post(s).
September 6th, 2012 1:38pm