Results 1 to 5 of 5

Thread: automatic script to delete file

  1. #1
    Join Date
    Oct 2005
    Posts
    190

    automatic script to delete file

    Hello everyone,
    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. #2
    Join Date
    Dec 2007
    Posts
    1,736

    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. #3
    Join Date
    Oct 2005
    Posts
    190

    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
    In this case, the .Bat should delete the directory r132_1.

    Thank you in advance.
    I may b a dreamer, but I'm not the only one

  4. #4
    Join Date
    Dec 2007
    Posts
    1,599

    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
    '-----------------------------------------------

  5. #5
    Join Date
    Jun 2006
    Posts
    623

    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

Similar Threads

  1. How to make a script that can find and delete a file?
    By sabboy in forum Software Development
    Replies: 1
    Last Post: 23-04-2012, 10:48 PM
  2. How to Delete Vista Automatic Updates Notification
    By jhon in forum Operating Systems
    Replies: 5
    Last Post: 20-01-2010, 05:57 AM
  3. Replies: 2
    Last Post: 26-11-2008, 06:56 PM
  4. Replies: 0
    Last Post: 26-11-2008, 04:11 PM
  5. Script for automatic update
    By Zombi in forum Software Development
    Replies: 6
    Last Post: 20-11-2008, 06:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,893,277.85408 seconds with 16 queries