|
| ||||||||||
| Tags: file, script |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| ||||
| ||||
| automatic script to delete file
I am currently trying to create a script that can automatically delete the file of an earlier date. I have a surveillance camera that creates files .Avi per 5min continuously. I would like to delete all the files> to 7 days early each morning by double clicks. The problem is that the camera sometimes creates other directories in the original. The program will delete the files in a directory, but will also see if there are other directories in it, to do the same procedure. Thank you in advance for any reply.
__________________ I may b a dreamer, but I'm not the only one |
|
#2
| ||||
| ||||
| Re: automatic script to delete file
It is possible to delete files in subdirectories: del /s *.avi I do not know what it is possible to compare dates. With VBS, you can create an equivalent solution, and it is still double-click. |
|
#3
| ||||
| ||||
| Re: automatic script to delete file
Is it possible to create one .Bat that: if there is a / the directory (s), and if they are empty in the directory "D: / camera example: Code: D:/camera/ /r132_1 /r132_2/ /blabla.avi /blabla2.avi Thank you in advance.
__________________ I may b a dreamer, but I'm not the only one |
|
#4
| ||||
| ||||
| Re: automatic script to delete file
Try to setup the Scheduled Tasks for the VBScript below. Hope it will help. WARNING!!!: Make sure to backup your source folder before testing. This script won't place your files into Recycle Bin. Since this script base on date created of the file, you should test to delete your files from its original location. If you copy your files to another location the date created will change to the current date then no file match with your criteria to delete. '-------------- CleanUp.vbs -------------------- Option Explicit Dim fso Set fso = CreateObject("Scripting.FileSystemObject") DeleteFiles fso.GetFolder("C:\Test") '<----- Change this folder name to match with your case. Sub DeleteFiles(srcFolder) Dim srcFile If srcFolder.Files.Count = 0 Then Wscript.Echo "No File to Delete" Exit Sub End If For Each srcFile in srcFolder.Files If DateDiff("d", Now, srcFile.DateCreated) < -7 Then fso.DeleteFile srcFile, True End If Next Wscript.Echo "Files Deleted successful" End Sub '-----------------------------------------------
__________________ Education, Career and Job Discussions |
|
#5
| ||||
| ||||
| Re: automatic script to delete file
Try this - name it 'DelOldFiles.vbs 'DelOldFiles.vbs Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject") Dim objOutputFile 'I'd recommend settting strSourceFolder to a 'temporary' folder if this data is important 'Always a good idea when testing "your" version...mine works in my environment, but you never know... ![]() strSourceFolder = "C:\Testing" Set objOutputFile = objFSO.CreateTextFile("C:\FilesRemoved.log") With objOutputFile .WriteLine "===========================" .WriteLine "Removal summary for " & Date .WriteLine "=-=-=-=-=-=-=-=-=-=-=-=-=-=" .WriteLine End With 'intDel is the number of days old you want to check for. I set it to 1 for testing. 'Change it to 30 in your case intDel = 1 dtOld = DateAdd("d", -intDel, Date) ProcessFolder(objFSO.GetFolder(strSourceFolder)) With objOutputFile .WriteLine .WriteLine "Process completed at " & Now .WriteLine "===========================" .Close End With Set objOutputFile = Nothing Set objFSO = Nothing wscript.quit Sub ProcessFolder(strSource) ProcessFiles strSource For Each fld In strSource.SubFolders ProcessFolder objFSO.GetFolder(fld) Next End Sub Sub ProcessFiles(strSrc) For Each fil In strSrc.Files 'If a file exists that hasn't been accessed in intDel days or more, delete it If DateDiff("d", fil.datelastaccessed, dtOld) >= intDel Then objOutputFile.WriteLine fil.Path & " was removed at " & Now objFSO.DeleteFile fil.Path End If Next End Sub |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "automatic script to delete file" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to make a script that can find and delete a file? | sabboy | Software Development | 1 | 23-04-2012 10:48 PM |
| How to Delete Vista Automatic Updates Notification | jhon | Operating Systems | 5 | 20-01-2010 04:57 AM |
| How to disable automatic file scanning after file download in Firefox | SKREECH | Windows Software | 2 | 26-11-2008 05:56 PM |
| Disable automatic file scanning after file download in firefox | hatred | Tips & Tweaks | 0 | 26-11-2008 03:11 PM |
| Script for automatic update | Zombi | Software Development | 6 | 20-11-2008 05:52 PM |