Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error deleting files

Status
Not open for further replies.

vgwprja

Programmer
Mar 27, 2008
24
0
0
US
I have a script where I loop through a folder and deletes certain files. The 1st loop works fine and file is deleted. On subsequent loops I get error "permisson denied 800A0046". I am running the script under administrator. Can someone help me here? Thank you.

If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If
 
My guess is that you have opened the file somewhere else in your code and never closed it. Please post the rest of your code.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Here is the complete code:

'VB Script - Archive FTP Files (pgp format)

Dim filesys, file, folderName, objFile, folderObj, objEmail, fileColl, objRegExp, newFile
Set filesys = CreateObject("Scripting.FileSystemObject")

folderName = "e:\ftpdata\fromtravelers\"
Set folderObj = filesys.GetFolder(folderName)
Set fileColl = folderObj.Files

folderName = "e:\ftpdata\fromclient\"
strFTPScriptFileName = folderName & "\FTP_Inbound_Files_from_Travelers.txt"

Set objRegExp = New RegExp
objRegExp.Pattern = ".asc" 'looking for files with = ".asc" extension
objRegExp.IgnoreCase = True

For Each objFile In fileColl
If objRegExp.Test(objFile.Name) Then

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If

Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)

strFTPServerName = "ftp.travelerspc.com"
strLoginID = "userid"
strPassword = "password"
strFTPServerFolder = "tovecellio_edi"

objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("cd " & strFTPServerFolder)
objMyFile.WriteLine ("prompt off")
objMyFile.WriteLine ("rename " & objFile.Name & " backup/" & objFile.Name)
bjMyFile.WriteLine ("disconnect")
objMyFile.WriteLine ("bye")
objMyFile.Close

'Execute the remote script.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True

End If
Next

Set objFSO = Nothing
Set objMyFile = Nothing
Set objShell = Nothing
 
Well you are closing the file properly so that isn't it. Is it possible that the ftp process is still running when you run it the second time?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top