| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
File deletion incompetance
Hi I have started to use the following code to auto delete video and picture files from our CCTV. But when it script starts to delete the files I still need to click ok to confirm the deletion can anyone help with bypassing this prompt.
OPTION EXPLICIT DIM strExtensionsToDelete,strFolder DIM objFSO, MaxAge, IncludeSubFolders ' ************************************************** ********** ' Setup ' ************************************************** ********** ' Folder to delete files strFolder = "C:\Video Records\" ' Delete files from sub-folders? includeSubfolders = true ' A comma separated list of file extensions ' Files with extensions provided in the list below will be deleted strExtensionsToDelete = "mpg,mpeg,jpg,jpeg" ' Max File Age (in Days). Files older than this will be deleted. maxAge = 31 ' ************************************************** ********** set objFSO = createobject("Scripting.FileSystemObject") DeleteFiles strFolder,strExtensionsToDelete, maxAge, includeSubFolders wscript.echo "Finished" sub DeleteFiles(byval strDirectory,byval strExtensionsToDelete,byval maxAge,includeSubFolders) DIM objFolder, objSubFolder, objFile DIM strExt set objFolder = objFSO.GetFolder(strDirectory) for each objFile in objFolder.Files for each strExt in SPLIT(UCASE(strExtensionsToDelete),",") if RIGHT(UCASE(objFile.Path),LEN(strExt)+1) = "." & strExt then IF objFile.DateLastModified < (Now - MaxAge) THEN wscript.echo "Deleting:" & objFile.Path & " | " & objFile.DateLastModified objFile.Delete exit for END IF end if next next if includeSubFolders = true then ' Recursive delete for each objSubFolder in objFolder.SubFolders DeleteFiles objSubFolder.Path,strExtensionsToDelete,maxAge, includeSubFolders next end if end sub |
|
#2
|
||||
|
||||
|
Instead of using the File object's Delete method, use the FileSystemObject's DeleteFile method.
Change this: Code:
objFile.Delete To this: Code:
objFSO.DeleteFile(objFile.Path)
__________________
Click the image if at any point you don't like my decision.Scripting problems? Windows questions? Ask the Windows Guru! |
![]() |
| Viewing: ASP Free Forums > System Administration > Windows OS > File deletion incompetance |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|