Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Could not figure out exactly what this code does
Message
 
 
À
03/06/2009 11:47:36
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01403230
Message ID:
01403420
Vues:
39
1. How can I modify this code to be able to exclude certain directories? Doesn't seem to be an easy way.

2. I guess it should be able to handle no FileSystemObject as well.

>I'm for the shorter loop without changing the path
>
>Briefly tested - Sequence of 'Scripting.FileSystemObject' seems OK
>
>
>
>#include	"FoxPro.h"
>#define TRUE	.t.
>#define FALSE	.f.
>*-------------------------------------------------------------------------------
>local QueueObj, SubfolderName
>
>
>if( SubFolders(@m.QueueObj, "D:\tmp") )
>
>	do while m.QueueObj.DeQueue(@m.SubfolderName)
>		?SubfolderName
>	enddo
>endif
>*-------------------------------------------------------------------------------
>function SubFolders(QueueObj, FolderName)
>
>	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 = 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)
>		
>		=m.QueueObj.EnQueue(m.SubfolderName)
>		
>		objSubFolders = 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
>
>*===============================================================================
>*===============================================================================
>*===============================================================================
>
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform