0

DropIt Project Software:

I would like to know if it is possible to copy (or move) folders based on the amount of files they contain? E.g. I have: Folder 1 (2 Files), Folder 2 (5 Files), Folder 3 (1 File). Files 1 and 2 need to be moved to another location, because they contain more than one file. File 3 needs to remain where it is, because it only contains 1 file.

Is it possible to define a rule or regular expression to help with this?

If it's possible to do this task with VBA, that would also be fine.

Best regards, Hendre

1 Answers1

0

The idea:

Sub Test()
    Call MoveFolder("C:\Test1", "C:\Test2", 1)
End Sub

Sub MoveFolder(strSource$, strTarget$, iCount%)
    Dim fso As FileSystemObject
    Dim fld As Folder
    Set fso = New FileSystemObject
    Set fld = fso.GetFolder(strSource)
    If fld.Files.Count > iCount Then
        fld.Copy strTarget
        fld.Delete Force:=True
    End If
End Sub
JohnyL
  • 6,894
  • 3
  • 22
  • 41
  • Hi JohnyL, thanks for the initial help. Unfortunately it is not working. I have replaced the C:\Test1 and 2 placeholders with the locations of the initial and final folders. The code is running, but the files are not being transferred to the destination folder. What could be the problem? – Hendré Swart May 07 '18 at 12:21