You are not logged in.

#1 11 Jul 2018 13:13

shreked
New Member
Registered: 10 Jul 2018
Posts: 2

Can anyone help on why a BAT command not deleting folders.

Hi

HHHEEEELLLLLPPPPPP its doing my head in and getting to the end of my fuse as it not doing what it supposed to do.

I have the following script (shown at bottom) that is supposed to delete .exe  subfolders  after a certain number of days based on date created.

I click on it and it appears to run but not deleting  subfolders  of which all are a 7z folders.
The reason that they are .exe folders is that they are 7zip files.

All the folders are on a network and donno if that has issues with it.

Today  Ive been playing around with it using "C" drive.  Ive unzipped a 7z file and it shows in the folder a subfolder  and the 7zfolder that ive unzipped.

I changed the script to "date modified"  as  I have nothing past date created apart from today.

If I save script as a .VBS it deletes the FOLDERS that are over the number of days specified but NOT the .EXE files  and it also comes up with error shown below

LINE 24
CHAR 17
ERROR OBJECT DOSENT SUPPORT THIS PROPERTY OR METHOD : "objFile.Datemodified"
CODE  800A01B6

If I save as a .BAT file it does nothing.

SCRIPT...

RemoveOldFiles "S:\CCTV Downloads\Chiltern Downloads", 30, ""
RemoveOldFiles "\\crcl.local\ApplicationData\BTPCCTVDownloads", 30, ""


Sub RemoveOldFiles(strFolder, intAge, strExt)

    ' Create file system object
    Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

    ' Access base folder
    Set objFolder = objFSO.GetFolder(strFolder)

    ' Look at each subfolder in the base folder
    For Each objSubFolder In objFolder.Subfolders

        ' Look at each file in this subfolder
        For Each objFile In objSubFolder.Files

            ' See if the extension matches desired (or if we want all)
            strFileExt = LCase(objFSO.GetExtensionName(objFile.Path))
            If strExt = "" Or strFileExt = LCase(strExt) Then

                ' See if the create date is old enough to delete, if so delete it
                intFileAge = DateDiff("d", objFile.DateCreated, Now)
                If intFileAge > intAge Then
                    objFile.Delete
                End If
            End If

        Next

        ' If folder is now empty, we purged its entire contents, so remove it
        If objSubFolder.Files.Count = 0 And objSubFolder.Subfolders.Count = 0 Then
            objSubFolder.Delete
        End If

    Next

End Sub

Any Ideas.


Thanks

Offline

#2 11 Jul 2018 13:24

shreked
New Member
Registered: 10 Jul 2018
Posts: 2

Re: Can anyone help on why a BAT command not deleting folders.

Im no experts at this at all but ive been reading through the script again and noticed this section.  Please excuse me for being thick but where it says 

 strFileExt = LCase

does that mean look for "LOWER CASE" as all my file names are in upper case or are only numbers .

' See if the extension matches desired (or if we want all)
            strFileExt = LCase(objFSO.GetExtensionName(objFile.Path))
            If strExt = "" Or strFileExt = LCase(strExt) Then

Offline

#3 12 Jul 2018 00:56

Simon Sheppard
Admin
Registered: 27 Aug 2005
Posts: 1,130
Website

Re: Can anyone help on why a BAT command not deleting folders.

[moved to VBscript section]

Offline

#4 12 Jul 2018 16:06

Pyprohly
Member
Registered: 26 Nov 2014
Posts: 37

Re: Can anyone help on why a BAT command not deleting folders.

That code is very clean, but I can’t say the same for your attempt at communicating the problem.

That VBScript function only deletes files in the immediate subfolders of the given folder, i.e., it doesn’t remove files from the given folder itself, nor does it traverse all subfolders.

Does this explanation align with your expectation of what the script does? If not, what needs to change?

Also, please clarify your aim more clearly. I’m confused about how 7z zip files are pertinent?

Offline

Board footer

Powered by