delete file permission denied using vb6

I am trying to Delete a text file but keep getting a permission denied error. I can Copy it but cannot Move or Delete it.
Who is Participating?
DblTMOConnect With a Mentor Author Commented:
I would like to thank those who offered solutions.  They would all worked if I had closed the Text Object. I had closed all the FSO but not the TSO. Sometimes it the easy/obvious things that stop you.
odd lieSenior Quality Assurance EngineerCommented:
This can happen when someone has the file in use, try to chech if the file is in use,
If in use , try to find the owner of the file and close that connection.

DblTMOAuthor Commented:
I am the owner. I am Importing the file into Access then St the FSO = Nothing. After that I need to Copy the file to a Backup directory. After the Copy I need to Delete the orginal.
You can delete using command prompt if you have any issues with deleting using Explorer.
1. Open command prompt
2. type this below command. I have used c:\windows\test.tmp as example file you want to delete:
del /f /q c:\windows\test.tmp

This should work!
Try this:

    Dim FSO As Object
    Set FSO = CreateObject("Scripting.FileSystemObject")
    FSO.DeleteFile "FileToBeDeleted", True

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.