Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 690

need to clean up a filesystem

$
0
0
Greetings,

I am currently writing a tool to be used in my department. It will be running on up to 70 devices at the same time. Since we're working on customers system we aren't allowed to use exe-files, that's why I chose to write a hta that's executing a vbs-file. To coordinate all those instances I chose to write files, one per instance, based on the computers name. And here is my problem: I need to clean it up daily.

Basically my request is: How can I delete every file in a specific folder with a creation date not equal to the current date? I literally have no clue...

This is what I have 'til now. The function "getKP" is called by a button from the hta-file. It obviously checks if the user has a file, deleting it if it exists, creating it if it doesn't. So everybody can manually checkout. But often enough my users forget to do that, that's why I need to sometimes clean after them. Can you tell me how to achieve that?

Code:

function checkKP()
        Dim f, sPath, list, iCount, valColor, fName, fObj, objFSO, objFile
       
        KPBtn.setAttribute "style", "background-color:#5c5656;"
       
        sPath = cenTempFolder & "\kurzpause\"
       
        Set list = CreateObject("ADOR.Recordset")
        list.Fields.Append "name", 200, 255
        list.Fields.Append "date", 7
        list.Open
       
        dbQuery = "SELECT value FROM config WHERE name = 'Kurzpausen'"
        iKP = dbCall(dbQuery, 1)
        totalKP.innerHTML = iKP
       
        For Each f In fso.GetFolder(sPath).Files
                list.AddNew
                Set objFSO = CreateObject("Scripting.FileSystemObject")
                Set objFile = objFSO.GetFile(f.Path)
                list("name").Value = objFSO.GetFileName(objFile)
                list("date").Value = f.DateCreated
                list.Update
        Next
       
        list.Sort = "date ASC"
        If not list.EOF Then
                list.MoveFirst
                iCount = 0
               
                Do Until list.EOF
                        fName = list("name").Value
                        'set fObj = document.GetElementByID(fName)
                        If iCount < iKP Then
                                valColor = "#33FF33"
                        Else
                                valColor = "#ffaa00"
                        End If
                        If fName = sUser Then
                                KPBtn.setAttribute "style", "background-color:" & valColor & ";"
                        End If
                        'fObj.setAttribute "style", "color:" & valColor
                        iCount = iCount + 1
                        list.MoveNext
                Loop
        End If
        list.Close
        If iCount >= iKP Then
                iCount = iKP
        End If
        iFreeKP = iKP - iCount
        currentKP.innerHTML = iFreeKP
End Function

function getKP()
        Dim a, sPath, sFirstname
        sPath = cenTempFolder & "\kurzpause\" & sUser
        If FSO.FileExists(sPath) Then
                FSO.DeleteFile sPath
        Else
                set a = FSO.CreateTextFile(sPath, false)
                a.WriteLine(sComputer)
                a.Close()
        End If
End function


Viewing all articles
Browse latest Browse all 690

Latest Images

Trending Articles



Latest Images