Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cecil Champenois
  Where is Cecil Champenois?
 Little Elm
 Texas - United States
 Cecil Champenois
 To: Greg Green
  Where is Greg Green?
 
 Georgia - United States
 Greg Green
 Tags
Subject: RE: ADIR() Limitations
Thread ID: 416156 Message ID: 416165 # Views: 38 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Databases, Tables and SQL Server
Date: Monday, December 22, 2014 9:56:15 PM         
   


> >
> > Yeah, you are right. I see that ADIR is also picking up the . and .. as if they were files. So, the subscript ends up out of range.
> >
> > Cecil Champenois, Jr.
>
> You have to look at the file mask value in ADIR and the file type (directory or file). In the result array of values the file type is given by column 5. But an array is limited to 65K elements or memory available.

I corrected some of my code and it seems to have worked as follows:
I used CHDIR but I don't think it had any actual impact on the code working. ADIR() needed the default to be set to where the folders were.
SET TALK OFF
SET DELETED ON
SET CENTURY ON

lcPreviousDefault=SYS(5) + SYS(2003)	&& "E:\Dev\KMart_Sears_2012"
*SET PATH TO (lcPreviousDefault)
IF NOT USED("KMartSearsFiles2012")
	USE lcPreviousDefault + "\KMartSearsFiles2012" IN 0 SHARED
ENDIF
lcStartDefault="V:\Email_Attachments\KMart_Sears\2012\Att_Ex"
SET DEFAULT TO (lcStartDefault)

* Pick up the directories/folders names into an array.
lnFolders=ADIR(aKMartSearsFolders, "*", "D")
* Loop through the first set of folders.

FOR i = 1 TO lnFolders
	lcFolderName=aKMartSearsFolders[i,1]
	IF lcFolderName <> "." AND lcFolderName <> ".."
		* Change Directory to the first level of folders. We eventually go
		* down two folders form the default starting folder.
		CHDIR (lcFolderName)
		SET DEFAULT TO (lcStartDefault + "\" + lcFolderName)
		* Get the second set of folders.
		lnFolders2=ADIR(aKmartSearsFolders2, "*", "D")
		FOR j = 1 TO lnFolders2
			lcFolderName2=aKMartSearsFolders2[j,1]
			IF lcFolderName2 <> "." AND lcFolderName2 <> ".."
				CHDIR (lcFolderName2)
				SET DEFAULT TO (lcStartDefault + "\" + lcFolderName + "\" + lcFolderName2)
				* Actual FILE LEVEL NOW.
				* Now gather up MSG_DT and FileNames values.
				lnNumberOfFiles=ADIR(aFiles)	&& ADIR() doesn't pick up the . and .. as files.
				*lnNumberOfFiles=ALEN(aFiles,1)	&& Get # of FILES/ROWS.
				FOR k = 1 TO lnNumberOfFiles
					lcFileName=aFiles[k,1]
					dFolderDate=;
						CTOD(;
						SUBSTR(lcFolderName2,5,2) + "/" + ;
						SUBSTR(lcFolderName2,7,2) + "/" + ;
						LEFT(lcFolderName2,4))
					INSERT INTO KMartSearsFiles2012 ;
							(Msg_Dt, FileName, lFound) ;
						VALUES ;
							(dFolderDate, lcFileName, .F.)
				ENDFOR
				SET DEFAULT TO (lcStartDefault + "\" + lcFolderName)
			ENDIF
		ENDFOR
		SET DEFAULT TO (lcStartDefault)
	ENDIF
ENDFOR
SET DEFAULT TO (lcPreviousDefault)

RETURN


Cecil Champenois, Jr.

ENTIRE THREAD

ADIR() Limitations Posted by Cecil Champenois @ 12/22/2014 7:36:30 PM
RE: ADIR() Limitations Posted by Tore Bleken @ 12/22/2014 7:45:21 PM
RE: ADIR() Limitations Posted by Cecil Champenois @ 12/22/2014 8:50:46 PM
RE: ADIR() Limitations Posted by Greg Green @ 12/22/2014 9:02:11 PM
RE: ADIR() Limitations Posted by Cecil Champenois @ 12/22/2014 9:56:15 PM
RE: ADIR() Limitations Posted by Ali Koumaiha @ 12/22/2014 10:37:27 PM