Reputation:
Is possible rename a folder with files? The code below create a folder and save the attachments in there. After I need to rename this folder with a date which is in the second line of file saved. I can retrieve the date, but the code can't rename the folder.
Option Explicit
Public Sub SalvarAnexo(Item)
Dim Atmt As Attachment
Dim FileName As String
Dim objFSO As Object
Dim objFile As Object
Dim strData As String
Dim caminhoTemp As String
Dim caminhoFinal As String
Dim caminhoFtp As String
'MsgBox "Mensagem Recebida de " & Item.Sender & "!"
caminhoTemp = "C:\temp"
caminhoFinal = "C:\"
For Each Atmt In Item.Attachments
If Right$(Atmt.FileName, 3) = "TXT" Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
FileName = caminhoTemp & "\" & Atmt.FileName
Atmt.SaveAsFile FileName
Set objFile = objFSO.OpenTextFile(FileName, 1)
strData = objFile.ReadLine
strData = objFile.ReadLine
strData = Left$(strData, 10)
strData = Replace(strData, "-", "")
caminhoFinal = caminhoFinal & strData
Name caminhoTemp As caminhoFinal
objFile.Close
MsgBox "Your date is " & strData
End If
Next Atmt
End Sub
Upvotes: 1
Views: 133
Reputation: 55682
You can do this directly without the overhead of the FileScriptingObject
with
Name "C:\oldname" As "C:\newname"
In your particular case there isn't a huge saving as the FileScriptingObject
has been invoked already to open the text file.
Upvotes: 1
Reputation: 581
objFSO.MoveFolder("c:\oldname", "c:\newname")
The files in the "oldname" folder should be all closed.
Edit per Tomalak below (thanks!):
You can get the folder object and rename it:
Set fdr = objFSO.GetFolder("oldname")
fdr.Name = "newname"
The files in the "oldname" folder should be all closed.
"oldname" is Fullsplec.
"newname" is just the name.
Upvotes: 2