Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Needing a batch file to delete all files in a folder older than 5 days old  (Read 41881 times)

0 Members and 1 Guest are viewing this topic.

WEW

    Topic Starter


    Rookie

    Hey I need a batch file to delete all .avi files in a folder older than 5 days old. I looked at the set, for, if commands, and for examples , but so far can't find any examples that help me figure out how to use the commands,I have read the if,for,set/? , but i guess i am to inexperienced to understand without some examples of their uses.... I bought a security camera and see that it will keep me very busy sorting the files out. I don't know if it's possible or not but would appreciate any help... I have no knowledge using the for, set, and if commands... did look through the forums, but didn't find anything that will help me yet, but will keep searching.... any help would be greatly appreciated...Thanks WEW. 


    I'm running a dell dimension E510 with Processor Intel(R) Pentium(R) D CPU 3.00GHz
    Processor Speed 2.92 GHz
    Memory (RAM) 1024 MB
    Operating System Microsoft Windows XP Professional
    Operating System Version 5.1.2600
    « Last Edit: August 05, 2008, 07:53:32 PM by WEW »

    DJFLuFFY



      Rookie

      I am looking for the same script so please answer this one


      Many thanks in advance

      Carbon Dudeoxide

      • Global Moderator

      • Mastermind
      • Thanked: 169
        • Yes
        • Yes
        • Yes
      • Certifications: List
      • Experience: Guru
      • OS: Mac OS
      Homework?   ::)

      Jacob



        Hopeful

        Thanked: 1
        • Experience: Expert
        • OS: Windows XP
        Homework?   ::)
        Quote
        I'm running a dell dimension E510 with Processor Intel(R) Pentium(R) D CPU 3.00GHz
        Processor Speed 2.92 GHz
        Memory (RAM) 1024 MB
        Operating System Microsoft Windows XP Professional
        Operating System Version 5.1.2600

        DJFLuFFY



          Rookie

          homework????

          don't understand

          Jacob



            Hopeful

            Thanked: 1
            • Experience: Expert
            • OS: Windows XP
            homework????

            don't understand
            He thinks this persons query is a school assignment.

            DJFLuFFY



              Rookie

              LOL

              i need it to delete my logfiles and .torrent files that i don't use

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              homework????

              don't understand

              It's code for the paranoia factor.

              Batch code does not handle date/time arithmetic very well. Dates can be formatted many different ways. The actual format can be extracted from the registry adding overhead to your batch file.

              Aging files is simple arithmetic provided the current day of month is greater than age factor. When it's not, you may be dealing with multiple past months and their cumulative days.

              Most scripting languages for Windows have functions to specifically handle dates. Any reason your solution must be batch code?

               8)


              The true sign of intelligence is not knowledge but imagination.

              -- Albert Einstein

              Carbon Dudeoxide

              • Global Moderator

              • Mastermind
              • Thanked: 169
                • Yes
                • Yes
                • Yes
              • Certifications: List
              • Experience: Guru
              • OS: Mac OS
              You can simply do a search of the computer for .log .txt and .torrent and then sort them by date.

              Quote
              It's code for the paranoia factor.
              Heh, you will know it's bad when I just ask 'Why'  :P

              DJFLuFFY



                Rookie

                if you have another script that does what i want it is welcome :)

                i am a PHP coder so i know the basics for programming but making a Batch is really different

                You can simply do a search of the computer for .log .txt and .torrent and then sort them by date.

                Quote
                It's code for the paranoia factor.
                Heh, you will know it's bad when I just ask 'Why'  :P

                this is how i work now, But it takes a lot of time to do.

                Sidewinder



                  Guru

                  Thanked: 139
                • Experience: Familiar
                • OS: Windows 10
                This little snippet is written in VBScript:

                Code: [Select]
                Set fso = CreateObject("Scripting.FileSystemObject")
                Set f = fso.GetFolder("c:\scripts")            'point to your directory
                Set fc = f.Files

                For Each objFile In fc
                If fso.GetExtensionName(objFile) = "avi" then
                If objFile.DateCreated < date - 5 Then
                WScript.Echo objFile & " " & objFile.DateCreated
                'fso.DeleteFile(objFile)  'commented out
                End If
                End If
                Next

                Save with a vbs extension and run from the command line as: cscript scriptname.vbs

                The delete function is currently commented out. Script will currently list files to be deleted. When you're ready, uncomment the delete function and comment the wscript.echo line.

                Good luck  8)

                The true sign of intelligence is not knowledge but imagination.

                -- Albert Einstein

                DJFLuFFY



                  Rookie

                  Thanks this works really great :)

                  only i have 2 new problems  :-[

                  because i forgot to tell you that it has to do the same with all the folders & subfolders

                  and now i can only select 1 extension by default it's avi. *.* works fine for me ;)


                  DJFLuFFY



                    Rookie

                    Thanks this works really great :)

                    only i have 2 new problems  :-[

                    because i forgot to tell you that it has to do the same with all the folders & subfolders

                    and now i can only select 1 extension by default it's avi. *.* works fine for me ;) < Yes i fixed this :)



                    But i still can't figure out how to include the subfolders

                    Sidewinder



                      Guru

                      Thanked: 139
                    • Experience: Familiar
                    • OS: Windows 10
                    The original code from the snippet closet had recursion built in. It took me days, hours, oh alright, a few minutes to rip it out. Should have gone with my gut feeling.;D

                    Again the delete function is commented. You can activate it when you're satisfied this works in your environment. Be careful, files deleted with this script do not make a pit stop in the recycle bin.

                    Code: [Select]
                    Set fso = CreateObject("Scripting.FileSystemObject")
                    Set f = fso.GetFolder("c:\scripts")           'point to your directory
                    Set colSubFolders = f.SubFolders

                    For Each objFolder in colSubFolders
                    ShowFiles objFolder
                    Next

                    Sub ShowFiles(Fld)
                    Set k = fso.GetFolder(Fld)
                    Set s = k.SubFolders
                    Set kf = k.Files

                    For Each objFile In kf
                    If fso.GetExtensionName(objFile) = "avi" then
                    If objFile.DateCreated < date - 5 Then
                    WScript.Echo objFile & " " & objFile.DateCreated
                                                    'fso.Deletefile(objFile)    'commented out
                    End If
                    End if
                    Next

                    For Each SubFolder In s
                    ShowFiles SubFolder
                    Next
                    End Sub

                     8)
                    The true sign of intelligence is not knowledge but imagination.

                    -- Albert Einstein

                    DJFLuFFY



                      Rookie

                      Thanks again :)

                      but i get an error when i try to delete files. the echo part works great :)




                      ps. the recycle bin is for Pussies  :P

                      [recovering disk space -- attachment deleted by admin]