I have windows service which tries to delete a file in the IIS web server. The file path in the IIS server is "E:\WebApp" . I am able to get list of all the files in this path. But un able to delete the file. I am getting the below error "[System.Unauthor izedAccessExcep tion] = {"Access to the path 'CR1100000043D2 0082009053331.P DF' is denied."}"
Both IIS server and Windows service machine have windows 2003 server OS. I am running the service as administrator user only.
I need java script or VB Script to delete old files in a folder and it's subfolders in a local computer. I have to call this script in a batch file or by windows scheduler tasks.
I have written the below VBScript to delete files and it is working fine. But I need the samething as batch(.bat) file with DOS commands.
Thanks
Manoj
Both IIS server and Windows service machine have windows 2003 server OS. I am running the service as administrator user only.
I need java script or VB Script to delete old files in a folder and it's subfolders in a local computer. I have to call this script in a batch file or by windows scheduler tasks.
I have written the below VBScript to delete files and it is working fine. But I need the samething as batch(.bat) file with DOS commands.
Code:
Option Explicit
Dim FSO, WshShell, Then_Date, WSHShellENV, TempFolder, Recycled ' variables needed for main program(local scope)
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject") ' a new object to gain access to a computer's file system
Set WshShell = WScript.CreateObject("WScript.Shell") ' an object in type specified
Set WSHShellENV = WSHShell.Environment("PROCESS")
Set drv = FSO.GetDrive("D")
DoDir FSO.GetFolder("D:\TUSA\TUSA\CallCentre\CustomerReports")
DoDir FSO.GetFolder("D:\TUSA\Tusa\CustomerPortal\CustomerReports")
Then_Date = DateAdd("d", -5, Date) ' Files older than 5 days
WScript.Echo "Cleaned Databases on " & Now & ". " & " Erased Files older than " & Then_Date
Sub DoDir(Folder)
Dim i, File, SubFolder, fstr, pos, last_mod ' variables needed for function
Dim Now_Date, Then_Date ' variable used for today's date
Now_Date = Date ' loads today's date into variable Now_Date
Then_Date = DateAdd("d",-5, Now_Date) ' Files older than 5 days
Dim Findstr(0) ' an array named Findstr with array element one
Findstr(0) = ".PDF" ' loads into array element 0, the .txt file extension
For Each File In Folder.Files ' For each file in folder.files
FStr = UCase(File.Path)
'WScript.Echo(FStr)
Pos = 0
for i = 0 to 0
if ((instr(FStr, Findstr(i)) > 0) And (File.DateCreated < Then_Date)) then
' check whether there exists a string inside FStr
' which has an extension of any of the elements of FindStr
'WScript.Echo(FStr) ' echos file string
File.delete ' if there is, simply delete it
Exit For
End if
Next
Next
For Each SubFolder in Folder.SubFolders
DoDir SubFolder
Next
End Sub
Sub ClearFolder(Folder)
Dim File, SubFolder
For each file in Folder.Files
File.delete(True)
next
'For Each SubFolder in Folder.SubFolders
' SubFolder.Delete(True)
'Next
End Sub
Manoj
Comment