FileSystem

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

FileSystem

Post by D Willett »

Hi

A friend has been hacked over the weekend and corrupted his total business database and management system.
His only rescue is a separate server he has containing his image folders of work undertaken.

I could do with some code to read and return folder names modified or created after 09/02/2013.
I looked at some old code of mine but I don't have what is required. I hope to create a printout or csv of the folder names so he can rebuild his database.

The folders are held in "L:\mmpdf\ConsoleFiles" and each folder is named by job number, ie:

121345
125478
254177

etc etc

( I hear many have been hacked ! )
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: FileSystem

Post by HansV »

The following code can be run from VB6 or from any Office application (Word, Excel, ...).
It uses the Scripting Runtime library, but with late binding, so you don't need to set a reference.

Code: Select all

' Earliest date
Private Const dtmFrom = #2/9/2013#
Private f As Long

Sub ListFolders()
    ' Folder to start in. Modify as needed
    Const strPath = "L:\mmpdf\ConsoleFiles"
    ' File to save results in. Modify as desired.
    Const strFile = "L:\mmpdf\FolderList.txt"
    Dim fso As Object
    Dim fld As Object
    f = FreeFile
    Open strFile For Output As #f
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(strPath)
    ProcessFolder fld
    Close #f
End Sub

Sub ProcessFolder(fld As Object)
    Dim sfl As Object
    On Error GoTo ExitHere
    For Each sfl In fld.SubFolders
        If sfl.DateCreated >= dtmFrom Or sfl.DateLastModified >= dtmFrom Then
            Print #f, sfl.Path
        End If
        ProcessFolder sfl
    Next sfl
ExitHere:
End Sub
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: FileSystem

Post by D Willett »

Cheers Hans

Is this date format correct from your code?
Private Const dtmFrom = #2/9/2013# or should I change it to uk format #09/02/2013# ??
Cheers ...

Dave.

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: FileSystem

Post by HansV »

No, literal dates in VBA *must* be specified in US date format mm/dd/yyyy. The same holds for SQL.
Best wishes,
Hans

D Willett
SilverLounger
Posts: 1728
Joined: 25 Jan 2010, 08:34
Location: Stoke on Trent - Staffordshire - England

Re: FileSystem

Post by D Willett »

Thanks |Hans. I have it running as we speak.

( It's worked and returned the txt file of all folders created or modified post 08/02/2013.

Great big thanks Hans ( as always )

Kind Regards
Cheers ...

Dave.