Directory and File Detection

V

Varne

Hi

Can I have help on this please?

I set up files 'Hours' and 'Rate' under each directories 'Jan' to 'Dec'
under directory Lee. I do not want him(Lee) to add a 13th directory under
Lee.

If he does create a 3rd file or 13th directory how can I spot it through VBA
codes?

Thank You.

M Varnendra
 
J

Joel

Folder = "c:\temp\"
Count = 0
FName = dir(Folder & "*.*")
Do while FName <> ""
Count = Count + 1
FName = dir()
loop
 
J

Joel

try this code

Sub Macro1()

Set fso = CreateObject _
("Scripting.FileSystemObject")

LeeFolder = "c:\temp"

Set Folder = _
fso.GetFolder(LeeFolder)

If Folder.subfolders.Count > 0 Then
For Each sf In Folder.subfolders

'check if Folder Name is a month
FoundMonth = False
For MonthNum = 1 To 12
MonthNm = MonthName(MonthNum, abbreviate:=True)
If UCase(MonthNm) = UCase(sf.Name) Then
FoundMonth = True
Exit For
End If
Next MonthNum
If FoundMonth = False Then
MsgBox ("Folder " & sf.Path & " is not a month")
Else
FName = UCase(Dir(sf.Path & "\*.*"))
If FName <> "HOURS" And _
FName <> "RATE" Then

MsgBox ("Extra File : " & sf.Path & "\" & FName)
End If
End If

Next sf
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top