Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any way of comparing files in two folders
Message
From
17/10/2004 09:54:25
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00952065
Message ID:
00952068
Views:
11
>Hi.
>Anybody know of a way to check 2 folders and display any files that exist in one folder but not the other ?
>(I am Zipping all files in a folder using two different Zip programs but coming up with a different count of the files .. of about 3,500 files , I am getting a difference of c 300)
>
>Regards,
>
>Gerard


Gerard,

(1) you can create a cursor filled with the filenames of both arrays.
You then
select FileName, count(*) ;
   from cursor CursorName ;
   group by 1 ;
        having (count(*) = 1)
(2)You start with sorting both arrays, then you do a merge, except that you do not copy when both elements are equal

I've made a quick example for a one dimensional array. (not fully tested)
*---------------------------------------------------------------------------
function Do_it()
	
	local aa[3], bb[2], ResultArray[1], n
	aa[1] = 'ABC'
	aa[2] = 'DEF'
	aa[3] = 'GHI'
	
	dime bb[2]
	bb[1] = 'DEF'
	bb[2] = 'ZZZ'
	
	n=ArrayCompare(@aa, @bb, @ResultArray)
	n=ArrayCompare(@aa, @aa, @ResultArray)
	
	assert FALSE
endfunc
*---------------------------------------------------------------------------
function ArrayCompare(Array1, Array2, ResultArray)

	local i, j, n, nRows1, nRows2
	
	
	=asort(Array1)
	=asort(Array2)
	
	nRows1 = alen(Array1, 1)
	nRows2 = alen(Array2, 1)
	
	i = 1
	j = 1
	
	n = 0
	
	dime ResultArray[min(m.nRows1 + m.nRows2, 65000)]
	
	do while (m.i <= m.nRows1) and (m.j <= m.nRows2 )
	
		do case
		case ( Array1[m.i] == Array2[m.j] )
			i = m.i + 1
			j = m.j + 1
		
		case ( Array1[m.i] < Array2[m.j] )
			n = m.n + 1
			ResultArray[ m.n ] = Array1[m.i]
			i = m.i + 1
		
		otherwise
			n = m.n + 1
			ResultArray[ m.n ] = Array2[m.j]
			j = m.j + 1
		
		endcase
	enddo
	
	do case
	case (m.i <= m.nRows1)
		dime ResultArray[ m.n + m.nRows1 - m.i + 1]
		=acopy(Array1, ResultArray, m.i, m.nRows1 - m.i + 1, m.n + 1)
		
		n = m.n + m.nRows1 - m.i + 1
		
	case (m.j <= m.nRows2)
		dime ResultArray[ m.n + m.nRows2 - m.j + 1]
		=acopy(Array2, ResultArray, m.j, m.nRows2 - m.j + 1, m.n + 1)
		n = m.n + m.nRows2 - m.j + 1
	
	otherwise
		dime ResultArray[ max(m.n, 1) ]
	
	endcase
	
	return m.n

		
endfunc
*---------------------------------------------------------------------------
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform