Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking directory for Files

Status
Not open for further replies.

tmag

Programmer
Mar 31, 2003
3
0
0
US
Hello,

I have a directory on a fax server that will remain constant. The faxed in image files (.tif) in this directory are processed through an imaging application. I've created a script that reads the directory and creates the feed to the application. However, I want to check the directory for the existence of files before it proceeds with the rest of the script.

Seems like it should be simple but can't get it. I believe it's due property of the file collection.

Dim objFSO, FxFiles
Set objFSO = CreateObject("Scripting.fileSystemObject")
Set FxFiles = objFSO.GetFiles("c:\infax\*.tif")
If FxFiles = "" Then
GoTo NoFiles
Else
GoTo WrkFiles
End If

Appreciate any help and the expertise all of you offer!
 
The FSO doesn't have a "GetFiles( )" method. Instead you use GetFolder( ) and then examine the Folders and Files collections that the Folder returned by GetFolder( ) exposes as properties.

The online docs are here:


Downloadable docs are here:

 
dilettante,

Thanks for the help. I was mistaken, there is a GetFile() method, but I did try your recommendation with the GetFolder and examining the Files collection. The problem I am still experiencing though is in the "If" statement test. If I have a result of FxFiles.Files, what do I test against for an empty result.

Set FxFiles = objFSO.GetFolder("c:\infax\*.tif")
Set FlChk = FxFiles.Files

If FlChk = "" Then ...... doesn't work
If FlChk = Null Then ....... doesn't work
If FlChk = Nothing ....... doesn't work

all three return an invalid property assignment error.

Thanks again!
 
This is what I did

Code:
Sub ShowLeafFolders(Folder)
	Dim SubFolder
    For Each Subfolder in Folder.SubFolders
        'Wscript.Echo Subfolder.Path
        ShowLeafFolders Subfolder
		ShowFoldersDetails(Subfolder.Path)
    Next
'	ShowFoldersDetails(Folder.Path)
End Sub

Sub ShowFoldersDetails(Folder)
	Dim objShell
	Dim objFolder
	
	Dim FileCount
	Dim FolderCount
	Dim Item
	
	Dim startVal
	Dim displayNGName
	Set objShell = CreateObject("Shell.Application")
	Set objFolder = objShell.Namespace(LCase(Folder))

	FileCount = 0
	FolderCount = 0
	Dim i

	For Each Item in ObjFolder.Items
		If Item.IsFolder = True Then
			FolderCount = FolderCount + 1
		Else
			FileCount = FileCount + 1
		End If
	Next		
	
	If FolderCount = 0 Then
'		WScript.Echo "Folder Count = " & FolderCount

		StartVal = InStr(Folder, "nomadics_projects") + 17
		displayNGName = "nomadics.projects" & Join(Split(Mid(LCase(Folder),StartVal), "\"), ".")
			
'	    ReDim Preserve NewGroupNames(newFolderIdx + 1)
'	    ReDim Preserve NewFileCounts(newFolderIdx + 1)

		If (DebugOn) Then
		'	WScript.Echo  displayNGName & " = " & FileCount
		End If
		objNewGroupDy.Add displayNGName, FileCount

'		NewGroupNames(newFolderIdx) = displayNGName
'		NewFileCounts(newFolderIdx) = FileCount
		
'		newFolderIdx = newFolderIdx + 1
		
	End If
End Sub
 
Set FlChk = FxFiles.Files
If FlChk.Count > 0 Then MsgBox "You've got files"

Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top