VB Script permision denied when deleting file


I have a script that moves a file from 1 location to another then deletes the file from the folder the file was moved from.

The copy\move works but when it hits the line to delete the file i get an error thrown:

Permission denied.

I have set the folder to full rights (set to everyone with full permission) and also the the file itself but i still getr the error.

heres the code

' Move the text file to "Processed" by first copying across and then deleting from "ConvertXML" Folder
   strFile = strPath & "\ConvertXML\" & strName
   If FSO.FolderExists(strPath & "\ConvertXML\Processed\") Then
     FSO.CopyFile strFile, strPath & "\ConvertXML\Processed\",True

'This next line fails with 'Permission denied'
       FSO.DeleteFile (strPath & "\ConvertXML\" & strName), DeleteReadOnly
   End If
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Could the file be opened by another process?

Can you delete it from either a DOS command prompt, or Windows Explorer?

wilko1000Author Commented:
When i close the script i can delete the file using right click delete
Bill PrewCommented:
Okay, can you post the full script please.  It sounds like you may have opened the file for writing in the script, but not closed it yet?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

wilko1000Author Commented:
Hi Bill

I found out what it is.

I had set the file for reading....

Set oTS = FSO.OpenTextFile(File.Path, ForReading, True, TristateFalse)
    strFileData = oTS.readall

but not closed it.

Adding this line in...


Allowed the script to delete the file.

Simple things Bill, always the simple things, thanks for your help and ful points on its way
wilko1000Author Commented:
Analysis and root cause was spot on
Bill PrewCommented:
Great, glad that thought was helpful, and glad you located the problem, thanks for the feedback.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

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.