你的问题
首先,我认为错误是因为变量包含完整路径而不仅仅是文件名,所以你必须使用类似的表达式:
"D:\\Archive\\" + LEFT(RIGHT( @[User::Variable] , FINDSTRING(REVERSE( @[User::Variable] ) , "\\", 1) - 1),4)
详细解决方案
第一种方法 - 使用脚本任务
尝试使用脚本任务来实现此目的,只需选择您的变量作为ReadOnlyVariable
在脚本任务中。并使用类似的脚本(我用的是Vb.net)
Public Sub Main()
Dim strFile As String = Dts.Variables.Item("User::Variable").ToString
Dim strFilename As String = IO.Path.GetFileName(strFile)
'Create Directory
If Not IO.Directory.Exists("D:\Archive\" & strFilename.Substring(0, 4)) Then
IO.Directory.CreateDirectory("D:\Archive\" & strFilename.Substring(0, 4))
End If
'Copy File to destination
IO.File.Copy(strFile, "D:\Archive\" & strFilename.Substring(0, 4) & "\" & strFilename)
Dts.TaskResult = ScriptResults.Success
End Sub
第二种方法 - 使用文件系统任务
创建一个新变量@[User::DestinationPath]
并设置它的属性Evaluate As Expression
= True,然后使用以下表达式:
"D:\\Archive\\" + LEFT(RIGHT( @[User::Variable] , FINDSTRING(REVERSE( @[User::Variable] ) , "\\", 1) - 1),4)
可变截图
文件系统任务