Wednesday, January 20, 2010

Grab the filename for a file in a Folder

You will probably come across a file that is formatted like this


where we are dealing with the full timestamp in the name. As long as the file is the only file in the directory, we can use the script below:

Function Main()

Set objFSO =
objStartFolder = "\\DriveName\FolderName\"

Set objFolder = objFSO.GetFolder(objStartFolder)

Set colFiles = objFolder.Files
For Each objFile in colFiles
DTSGlobalVariables ("gv_FileName").Value =
objStartFolder & objFile.Name
Main = DTSTaskExecResult_Success

End Function

You now have the full path and filename in the global variable. Now, if there are multiple files in the directory, you will have the last file name in the global variable.

No comments: