Deletion - Permission Denied

Permission Denied while Deleting Temporary Files

Page 1 of 1

3 Replies - 4520 Views - Last Post: 18 November 2009 - 02:08 AM Rate Topic: -----

#1 Nash29  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 17-November 09

Deletion - Permission Denied

Posted 17 November 2009 - 10:27 PM

Hi there..
I'm currently working on a project application in which I'm dealing with multiple data reports. Use of multiple data reports are causing generation of multiple temporary(*.tmp) files in the application directory. So, I programmed a method to delete those temporary files from the app directory. B)

The code for the method goes as follows:

Public Sub deleteTMPFiles()  
	Dim oFSO As New FileSystemObject
	Dim oFolder As Folder, oSF As File

	Set oFolder = oFSO.GetFolder(App.Path)
	On Error GoTo KillErr
	For Each oSF In oFolder.Files
		If Right(oSF.Name, 4) = ".tmp" Then
			SetAttr oSF.Path, vbNormal
			Kill oSF.Path ' This line's generating error
		End If
	Next
	Exit Sub
KillErr:
	MsgBox Err.Description
End Sub


But the method is generating an error, when it comes to delete the file. It gives a description as Permission Denied :crazy:
I'm calling the method from MDIForm's unload event. I just want to delete the temporary files from the application directory. I've also tried the DeleteFile API function. It seemed as if the code ran but reflected no changes in the system. :blink:

Oh yeah.. I've also checked, the files aren't being used up by any of the processes. And I haven't even set or change any permissions these days.. ;)

Any help will be appreciated.. :D

This post has been edited by Nash29: 17 November 2009 - 10:30 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Deletion - Permission Denied

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Deletion - Permission Denied

Posted 17 November 2009 - 10:59 PM

What Operating System are you using.
Was This Post Helpful? 0
  • +
  • -

#3 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,889
  • Joined: 10-May 07

Re: Deletion - Permission Denied

Posted 17 November 2009 - 11:08 PM

Make sure the file isn't in use, or open by another program.
Was This Post Helpful? 0
  • +
  • -

#4 Nash29  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 24
  • Joined: 17-November 09

Re: Deletion - Permission Denied

Posted 18 November 2009 - 02:08 AM

I'm using Windows XP SP3..
And I've already made sure the files weren't in use..
Coz I've checked it multiple times.. :pirate: :D

Well, cheers already.. I didn't get the problem in the code..
But I've found an alternative. :D

I've created a small console program in C#.. that checks the *.tmp files
in its application directory and deletes it.

The code for that is as follows
(in C#)
using System;
using System.IO;

namespace DeleteTempFiles
{
	class Program
	{
		static void Main(string[] args)
		{
			DirectoryInfo di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
			FileInfo[] rgFiles = di.GetFiles("*.tmp");
			foreach (FileInfo fi in rgFiles)
			{
				fi.Delete();
			}
		}
	}
}


Heh.. Heh.. :D

So, I just copied the DeleteTempFiles.exe to my application directory
and I'm running it from my VB6 Application while unloading the MDIForm using Shell(). :rolleyes:

(In VB6)
Dim DeleteTempFiles
DeleteTempFiles = Shell(App.Path & "\DeleteTempFiles.exe")


That's it. Works like a charm.. :)

Thanx for your replies.. :D

This post has been edited by Nash29: 18 November 2009 - 02:43 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1