2013-05-31 37 views
0

我的lotus代理将文件分离并将它们放入一个文件夹 有时,这些文件具有相同的名称,因此它们被覆盖了 我想重命名文件之前将其保存到文件夹代理lotus:detach file ...并将它们重命名为加入时间

Set rtitem = curdoc.GetFirstItem("Body") 
If Not rtitem Is Nothing Then 
    If Isarray(rtitem.EmbeddedObjects) Then 
     Forall o In rtitem.EmbeddedObjects 
      If (o.Type = EMBED_ATTACHMENT) Then 
       fullpath = path + o.source 
       Call o.ExtractFile(fullpath) 
      End If 
     End Forall 
    End If 
End If 

你能告诉我,我可怎么办呢? 非常感谢 问候 DSEA

回答

4

如果您要添加的时间每次,那么你必须“分裂”的名和扩展名的文件名添加前值:

Dim strPath as String 
Dim strExtension as String 
Dim strFullPath as String 
Set rtitem = curdoc.GetFirstItem("Body") 
If Not rtitem Is Nothing Then 
    If Isarray(rtitem.EmbeddedObjects) Then 
     Forall o In rtitem.EmbeddedObjects 
      If (o.Type = EMBED_ATTACHMENT) Then 
       fullpath = path + o.source 
       If Instr(fullpath , ".") > 0 then 
        strPath = StrLeftBack(fullpath , ".") 
        strExtension = "." & StrRightBack(fullpath, ".") 
       Else 
        strPath = fullpath 
        strExtension = "" 
       End If 
       strFullPath = strPath & "-" & Format(Now , "yyyymmdd-hhnnss") & strExtension 
       Call o.ExtractFile(strFullPath) 
      End If 
     End Forall 
    End If 
End If 

当然你可以首先“检查”文件是否存在,并且只添加时间值(如果它不是唯一的):

Dim strExist as String 
... 
If (o.Type = EMBED_ATTACHMENT) Then 
    fullpath = path + o.source 
    strExist = Dir$(fullPath, 0) 
    If strExist <> "" then 'exists 
     If Instr(fullpath , ".") > 0 then 
      strPath = StrLeftBack(fullpath , ".") 
      strExtension = "." & StrRightBack(fullpath, ".") 
     Else 
      strPath = fullpath 
      strExtension = "" 
     End If 
     strFullPath = strPath & "-" & Format(Now , "yyyymmdd-hhnnss") & strExtension 
    Else 
     strFullPath = fullpath 
    End If 
    Call o.ExtractFile(strFullPath) 
End If 
相关问题