ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check if directory empty OR no of files in directory. (https://www.excelbanter.com/excel-programming/284457-check-if-directory-empty-no-files-directory.html)

Michael Beckinsale

Check if directory empty OR no of files in directory.
 
Hi All,

I am in the middle of writing code for a spreadsheet solution and need to
check whether a specific directory is empty or not.

Can anybody tell me what the code is to do that please. ?

Alternatively does anybody know the code to count the number of files in a
directory ? I could then apply an IF 0 type statement to achieve the same
result.

All suggestions gratefully received.

Regards

Michael beckinsale



Paul D[_2_]

Check if directory empty OR no of files in directory.
 
use the filesystemobject
Set fso = CreateObject("Scripting.FileSystemObject")
of the top of my head, I believe there is a files object
so fso.files.count 0

check the filesystemobject under help and you will see lots of examples
Paul

"Michael Beckinsale" wrote in message
...
Hi All,

I am in the middle of writing code for a spreadsheet solution and need to
check whether a specific directory is empty or not.

Can anybody tell me what the code is to do that please. ?

Alternatively does anybody know the code to count the number of files in a
directory ? I could then apply an IF 0 type statement to achieve the same
result.

All suggestions gratefully received.

Regards

Michael beckinsale





George Nicholson[_2_]

Check if directory empty OR no of files in directory.
 
Sub CountFiles()
Dim iCount As Integer
Dim x As Integer
Dim strPath As String

strPath = "C:\ParentFolder\TargetFolder\"
x = Len(Dir(strPath))
If x < 0 Then
Do
iCount = iCount + 1
x = Len(Dir)
Loop Until x = 0
MsgBox "There are " & iCount & " file(s)."
Else
MsgBox "There are no files."
End If
End Sub
--
George Nicholson

Remove 'Junk' from return address.


"Michael Beckinsale" wrote in message
...
Hi All,

I am in the middle of writing code for a spreadsheet solution and need to
check whether a specific directory is empty or not.

Can anybody tell me what the code is to do that please. ?

Alternatively does anybody know the code to count the number of files in a
directory ? I could then apply an IF 0 type statement to achieve the same
result.

All suggestions gratefully received.

Regards

Michael beckinsale






All times are GMT +1. The time now is 08:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com