Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Could not figure out exactly what this code does
Message
From
03/06/2009 12:11:34
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01403230
Message ID:
01403423
Views:
41
This message has been marked as a message which has helped to the initial question of the thread.
Easy it is
(1) add an optional parameter
(2) Skip the like(parameter)
#include	"FoxPro.h"
#define TRUE	.t.
#define FALSE	.f.
*-------------------------------------------------------------------------------
local QueueObj, SubfolderName


if( SubFolders(@m.QueueObj, "D:\tmp", '*vfp*') )

	do while m.QueueObj.DeQueue(@m.SubfolderName)
		?SubfolderName
	enddo
endif
*-------------------------------------------------------------------------------
function SubFolders(QueueObj, FolderName, FileSkeletonExclude)

	local Success
	Success = TRUE
	
	local StackObj, ColObj, SubfolderName
	StackObj = createObject('Stack')
	QueueObj = createobject('Queue')
	ColObj = createObject('Queue')
	
	local fsObj
	fsObj = createobject('Scripting.FileSystemObject')
	
	do case
	case !m.Success
	
	otherwise
		try
			objSubFolders = m.fsObj.GetFolder(m.FolderName).SubFolders
		
		catch
			assert FALSE
			Success = FALSE
		
		endtry
	
	endcase
	
	
	do case
	case !m.Success
	
	otherwise
		for each Subfolder in m.objSubFolders 
			=m.ColObj.EnQueue(m.Subfolder.Path)
		endfor
		
	endcase

	do while m.Success ;
			and m.StackObj.AppendFrom(m.ColObj, TRUE) ;
			and m.ColObj.Clear() ;
			and m.StackObj.Pop(@m.SubfolderName)
		
		if( !empty(m.FileSkeletonExclude) and like(m.FileSkeletonExclude, m.SubfolderName) )
			loop
		endif
		
		=m.QueueObj.EnQueue(m.SubfolderName)
		
		objSubFolders = m.fsObj.GetFolder(m.SubfolderName).SubFolders
		
		for each Subfolder in m.objSubFolders 
			=m.ColObj.EnQueue(m.Subfolder.Path)
		endfor
		
	
	enddo
	
	
	return m.Success
	
endfunc
*-------------------------------------------------------------------------------
*-------------------------------------------------------------------------------
*===============================================================================
*===============================================================================
*===============================================================================
define class Stack as CollectionBase

*-------------------------------------------------------------------------------
function Push(v)
	=m.this.Add(m.v)
endfunc
*-------------------------------------------------------------------------------
function Pop(v)
	
	if( empty(m.this.Count) )
		return FALSE
	endif
	v = m.this.Item(m.this.Count)
	=m.this.Remove(m.this.Count)
	
endfunc
*-------------------------------------------------------------------------------
function Peek(v)
	
	if( empty(m.this.Count) )
		return FALSE
	endif
	v = m.this.Item(m.this.Count)
	
endfunc
*-------------------------------------------------------------------------------
*-------------------------------------------------------------------------------
enddefine
*===============================================================================
*===============================================================================
*===============================================================================


*===============================================================================
*===============================================================================
*===============================================================================
define class Queue as CollectionBase

*-------------------------------------------------------------------------------
function EnQueue(v)
	=m.this.Add(m.v)
endfunc
*-------------------------------------------------------------------------------
function DeQueue(v)
	
	if( empty(m.this.Count) )
		return FALSE
	endif
	v = m.this.Item(1)
	=m.this.Remove(1)
	
endfunc
*-------------------------------------------------------------------------------
function Peek(v)
	
	if( empty(m.this.Count) )
		return FALSE
	endif
	v = m.this.Item(1)
	
endfunc
*-------------------------------------------------------------------------------
enddefine
*===============================================================================
*===============================================================================
*===============================================================================

*===============================================================================
*===============================================================================
*===============================================================================
define class CollectionBase as Collection

*-------------------------------------------------------------------------------
function Clear()
	
	=m.this.Remove(-1)
	
endfunc
*-------------------------------------------------------------------------------
function Empty()

	return empty(m.this.Count)
	
endfunc
*-------------------------------------------------------------------------------
function AppendFrom(ColObj, Reversed)
	
	local i
	
	do case
	case !m.Reversed
		for i = 1 to m.ColObj.Count
			=m.this.Add(m.ColObj.Item[m.i])
		endfor
	
	otherwise
		for i = m.ColObj.Count to 1 step -1
			=m.this.Add(m.ColObj.Item[m.i])
		endfor
	
	
	endcase
	

endfunc
*-------------------------------------------------------------------------------
enddefine

*===============================================================================
*===============================================================================
*===============================================================================

>1. How can I modify this code to be able to exclude certain directories? Doesn't seem to be an easy way.
>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform