Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FSO.DELETEFILE

1,462 views
Skip to first unread message

Matt Pollicove

unread,
Oct 3, 2002, 10:32:08 AM10/3/02
to
Can anyone tell me why this code is not working:

Set netObj = WScript.CreateObject("WScript.Network")
Set fso = wscript.CreateObject("Scripting.FileSystemObject")

TempIntFilePath = "c:\documents and settings\"+netobj.UserName + "\Local
Settings\Temporary Internet Files\*.*"
TempWinntPath = "c:\documents and settings\"+netobj.UserName + "\Local
Settings\temp\*.*"
Temp2Path = "c:\winnt\temp\*.*"
TempIntFilePath = ucase(tempintfilepath)
WinntTempPath = ucase(TempWinntPath)
Temp2Path = ucase (Temp2Path)
fso.DeleteFile TempIntFilePath, true
fso.DeleteFile TempWinntPath, true
fso.DeleteFile Temp2Path, true

I keep getting permission denied. being run on windows 2000, sp 3 under an
admin account.

thanks


Christoph Basedau

unread,
Oct 3, 2002, 11:01:44 AM10/3/02
to

"Matt Pollicove" <matt...@optonline.net> schrieb:

> Can anyone tell me why this code is not working:
> Set netObj = WScript.CreateObject("WScript.Network")
> Set fso = wscript.CreateObject("Scripting.FileSystemObject")
>
> TempIntFilePath = "c:\documents and settings\"+netobj.UserName + "\Local
> Settings\Temporary Internet Files\*.*"

> ...
> fso.DeleteFile TempIntFilePath, true
> ...


> I keep getting permission denied. being run on windows 2000, sp 3 under an
> admin account.

Temporary Internet Files are protected (not by r-Attribute).
Delete these Files from another user-account with admin rights
or by the IE-Deletion-Routine (which will leave half of the
TIFs)


mfg
Christoph

Ned Flanders

unread,
Oct 3, 2002, 11:02:34 AM10/3/02
to
One of the files is in use by something else. In my case I could delete the
first 2 but not the 3rd one (\winnt\temp) until I closed XEarth.exe and
PopupKiller.EXE - both maintain temp files with a lock on them. The first
one's a desktop toy I'm fond of, the second is (duh) a popup killer.
A better(?) method might be to enumerate all the files, then pop in an "on
error resume next" statement, then delete them one by one rather than using
wildcards. Unfortunately, vbscript will not skip files it can't access;
it'll just bomb out.


"Matt Pollicove" <matt...@optonline.net> wrote in message
news:OyIY6luaCHA.1744@tkmsftngp11...

Joe Fawcett

unread,
Oct 3, 2002, 11:08:18 AM10/3/02
to
Trying to delete the index.dat file causes this. I think you're better off
looping through the files and deleting one at a time as well as having an On
Error Resume Next around the deletion part.
Joe

"Matt Pollicove" <matt...@optonline.net> wrote in message
news:OyIY6luaCHA.1744@tkmsftngp11...

matt pollicove

unread,
Oct 3, 2002, 3:27:37 PM10/3/02
to
Do you have some sample code in this regard or know where I can get it?

thanks
"Joe Fawcett" <joefa...@hotmail.com> wrote in message
news:OFOUT6uaCHA.2588@tkmsftngp12...

Torgeir Bakken (MVP)

unread,
Oct 3, 2002, 5:07:16 PM10/3/02
to
matt pollicove wrote:

> Do you have some sample code in this regard or know where I can get it?

Hi

Here is a Michael Harris script that deletes files older than x days using the
filesystemobject. You set the folder the script starts looking in, and the value

of the bIncludeSubFolders parameter tells it to include subfolders or not.

It handles locked files.


' folder to start search in...
path = "c:\temp"

' delete files older than 7 days...
killdate = date() - 7

arFiles = Array()
set fso = createobject("scripting.filesystemobject")

' Don't do the delete while you still are looping through a
' file collection returned from the File System Object (FSO).
' The collection may get mixed up.
' Create an array of the file objects to avoid this.
'
SelectFiles path, killdate, arFiles, true

nDeleted = 0
for n = 0 to ubound(arFiles)
'=================================================
' Files deleted via FSO methods do *NOT* go to the recycle bin!!!
'=================================================
on error resume next 'in case of 'in use' files...
arFiles(n).delete true
if err.number <> 0 then
wscript.echo "Unable to delete: " & arFiles(n).path
else
nDeleted = nDeleted + 1
end if
on error goto 0
next

msgbox nDeleted & " of " & ubound(arFiles)+1 _
& " eligible files were deleted"


sub SelectFiles(sPath,vKillDate,arFilesToKill,bIncludeSubFolders)
on error resume next
'select files to delete and add to array...
'
set folder = fso.getfolder(sPath)
set files = folder.files

for each file in files
' uses error trapping around access to the
' Date property just to be safe
'
dtlastmodified = null
on error resume Next
dtlastmodified = file.datelastmodified
on error goto 0
if not isnull(dtlastmodified) Then
if dtlastmodified < vKillDate then
count = ubound(arFilesToKill) + 1
redim preserve arFilesToKill(count)
set arFilesToKill(count) = file
end if
end if
next

if bIncludeSubFolders then
for each fldr in folder.subfolders
SelectFiles fldr.path,vKillDate,arFilesToKill,true
next
end if
end sub


--
torgeir
Microsoft MVP Scripting and WMI
Porsgrunn Norway


David

unread,
Oct 4, 2002, 3:36:46 PM10/4/02
to

"Torgeir Bakken (MVP)" <Torgeir.B...@hydro.com> wrote in message
news:3D9CB184...@hydro.com...

can you please explain, "why is that when i delete files this way"
they are still visible in explorer..... it appears that the files *Have Not*
been deleted which causes me to pull hair out..

when i want to delete a file, *That's What I Mean* delete it from my
system, gone, adios, asta_la_Vista, bye bye..

i have WSH 5.6
Win 98 (Final)

David


Michael Harris (MVP)

unread,
Oct 4, 2002, 7:11:25 PM10/4/02
to
>
> can you please explain, "why is that when i delete files this way"
> they are still visible in explorer..... it appears that the files
> *Have Not* been deleted which causes me to pull hair out..
>
> when i want to delete a file, *That's What I Mean* delete it from my
> system, gone, adios, asta_la_Vista, bye bye..
>
> i have WSH 5.6
> Win 98 (Final)
>

If you look at the code, all errors for failed deletes are trapped and reported in order to not be stopped by files in use. There could be other reasons such real access denied due to permissions, but that is the exception rather than the rule. Files that don't delete using that script are generally those that are in use. Make sure there are no open browser instances when you run the script to minimize that chance.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US


Torgeir Bakken (MVP)

unread,
Oct 4, 2002, 8:52:47 PM10/4/02
to
"Michael Harris (MVP)" wrote:

> David wrote:
> >
> > i have WSH 5.6
> > Win 98 (Final)
> >
>
> If you look at the code, all errors for failed deletes are trapped and reported in order to not be stopped by files in use. There could be other reasons such real access denied due to permissions, but that is the exception rather than the rule.

Especially on Win 98 ;-)

0 new messages