Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Ribeiro
Specialist
Specialist

Apagar arquivos antes de atualizar na pasta

O código vba abaixo esta correto.

Mas antes de atualizar novos arquivos preciso apagar os arquivos do caminho os arquivos em

FTPDir = "/public_html/teste/conquista/"

Alguma sugestão?

Set oShell = CreateObject("Shell.Application")

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Path to file or folder to upload

path = "C:\tmp\file.csv"

path = "C:\tmp\file1.csv"

Sub FTPUpload

On Error Resume Next

Const copyType = 16

'FTP Wait Time in ms

waitTime = 80000

'Configuración FTP

FTPUser = "xxxxx"

FTPPass = "xxxxxxx"

FTPHost = "xxxxxxxxxxxxx"

FTPDir = "/public_html/teste/conquista/"

strFTP = "ftp://" & FTPUser & ":" & FTPPass & "@" & FTPHost & FTPDir

Set objFTP = oShell.NameSpace(strFTP)

'Upload single file   

If objFSO.FileExists(path) Then

Set objFile = objFSO.getFile(path)

strParent = objFile.ParentFolder

Set objFolder = oShell.NameSpace(strParent)

Set objItem = objFolder.ParseName(objFile.Name)

objFTP.CopyHere objItem, copyType

End If

WScript.Sleep waitTime

End Sub

Neves
1 Solution

Accepted Solutions
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Agnaldo,

normalmente para verificar se tem o arquivo e apagar eu uso o seguinte código


Set filesys = Nothing

Set filesys = CreateObject("Scripting.FileSystemObject")

If filesys.FileExists("XXXXXXXXXXXXXXXXX") then

   filesys.DeleteFile "XXXXXXXXXXXXXXXXXX"

End If

ActiveDocument.GetApplication.Sleep 1000

Set filesys = Nothing

        

furtado@farolbi.com.br

View solution in original post

2 Replies
afurtado
Partner Ambassador/MVP
Partner Ambassador/MVP

Agnaldo,

normalmente para verificar se tem o arquivo e apagar eu uso o seguinte código


Set filesys = Nothing

Set filesys = CreateObject("Scripting.FileSystemObject")

If filesys.FileExists("XXXXXXXXXXXXXXXXX") then

   filesys.DeleteFile "XXXXXXXXXXXXXXXXXX"

End If

ActiveDocument.GetApplication.Sleep 1000

Set filesys = Nothing

        

furtado@farolbi.com.br
Ribeiro
Specialist
Specialist
Author

Obrigado Alessandro

Neves