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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Differing ADIR() results on WinNT and Win98

Status
Not open for further replies.

CFB

Programmer
Jan 11, 2001
74
US
Hi,

I've been getting different results using the ADIR() function with WinNT and Win98 operating systems. Here's the code I'm using:

cDir = alltr(getdir('c:', 'Select Directory for Process'))
nDirs = adir(aDirs, cDir+ '??????', 'D')

The nDirs variable should equal the number of subdirectories within the selected directory which have a length of 6 or less
The aDirs array should be populated with all subdirectory names within the selected directory which have a length of 6 or less and their relative directory information

The value that is being returned for nDirs is completely different on WinNT than it is on Win98. On WinNT all subdirectories within the selected directory with a length <= 6 are returned. On Win98 only the subdirectories within the selected directory that have an exact length = 6 are returned, so I don't get any of the smaller directory names. I’m assuming this has to do with the way the OS is handling the DIR function at the command prompt. Does anyone know if that assumption is correct and if it isn’t what could be causing this problem or if there is something I can do to account for it?

Thanks for the help.
 
it's how OS interpetes unknowns.

this will fix the problem but unforcunetly this causes duplicate records sense the way win98 or win95 works with the file system.

this is a dos hold back when the file system breaks the 6 char file limit, is when you get dupilcates

just do a OS check then run a defferent version of this code.

hope this helps

CREATE TABLE Dirs free ( fa c(25), fb n, fc d, fd c(25), fe c(10) )
cFile =&quot;&quot;
FOR i =1 TO 6
DIMENSION ADIRs(1,1)
cFile = cfile + '?'
nDirs = ADIR(adirs, 'c:\' + cfile , 'D')

IF !EMPTY(adirs[1])
APPEND FROM ARRAY adirs
RELEASE adirs
ENDIF

ENDFOR
 
Thanks for the idea, it's appreciated. Is there anyway to manipulate the way the OS is interpreting unknowns? The problem doesn't seem to be consistent on all Win98 machines I've tested on. Thanks again.
 
to my knowlegde no

when i ran it on three machines it did it the same way everytime
 
I forgot soemthing the sub diretories then the sub sub will be missed because the way win98 and 95 works.

Everytime you find a directory you have to restart your scan with one ? then remove the duplicate directories. On top of this you have to be very careful in that it does give you the parent directory.

Sorry for not saying this earlier
 
How I'm handling it now is I'm searching for everything and then determining if it's a directory afterwards. Here's the code I'm using now:

ndirs = adir(aList, addbs(cdir)+'*', 'D')
for x = 1 to ndirs
if !(aList[x,1] == '.') and !(aList[x,1] == '..')
and 'D' $ aList[x,5]
&&This is a directory
endif
endfor
 
I was playing with your code and it kept returning files along with Directories and it did not scan the sub directories

here is the code i came up with
I did it in a table and eliminated duplicated records.

I'm not very good with arrays.

It's not supper fast but i compared it to Microsoft search its about the same speed.




sET SAFETY OFF
CREATE TABLE Dirs free ( fa c(150), fb n, fc d, fd c(25), fe c(10) )
CDIR = 'C:\winnt\'

&& this piece gets the directories in the selected directory
&& sticks it in a table
ndirs = adir(aList, cdir +'*', 'D')
for x = 1 to ndirs
if DIRECTORY( CDIR + aList[x,1])
IF alist[x,1] != '.' and alist[x,1] != '..'
APPEND BLANK
REPLACE FA WITH CDIR + aLIST[X,1] + '\'
REPLACE FB WITH ALIST[X,2]
REPLACE FC WITH ALIST[X,3]
REPLACE FD WITH ALIST[X,4]
REPLACE FE WITH ALIST[X,5]
endif
endif
ENDFOR

&& this steps the through the file looking at file
&& i tryed SCAN ENDSCAN it just did the first records
&& created above. This appends new filesand just keeps
&& on going to no more directories are found
RELEASE alist
GO top
i = 1
DO WHILE !EOF()
GO TOP
GOTO i
cdir = ALLTRIM(fa)
ndirs = adir(aList, CDIR +'*',&quot;D&quot;)
for x = 1 to ndirs
if DIRECTORY( CDIR + aList[x,1])
IF alist[x,1] != '.' and alist[x,1] != '..'
APPEND BLANK
REPLACE FA WITH CDIR + aLIST[X,1] + &quot;\&quot;
REPLACE FB WITH ALIST[X,2]
REPLACE FC WITH ALIST[X,3]
REPLACE FD WITH ALIST[X,4]
REPLACE FE WITH ALIST[X,5]
endif
ENDIF
ENDFOR
RELEASE alist
i = i+1
IF i > RECCOUNT()
EXIT
endif
enddo

hope this helps
 
Thanks for the help. The &quot;'D' $ aList[x,5]&quot; piece of the code should differentiate between directories and files, but using &quot;directory(addbs(cdir)+aList[x,1])&quot; would definitely work as well. Both ways seem to work for me quite well. Thanks again for all the help folks.
 
The reason i had to do that way was i may not be in the VFP Search Path or Default Path which brakes your code. plus when i do a another search on the directory with . and .. (path looks like this &quot;c:\winnt\.\&quot; i get duplicate records. then i remeber that the . and .. are like indexes for that directory, So it just returns all the directories in the directory again.

 
As long as you pass the cDir variable the path of the directory you are wanting to search it should work fine. I created a method in which I use cDir and aDirs as parameters which can be passed and returned with the method. cDir would be the path you wanted to pass to the method and aDirs would be the array of subdirectories which would be passed back. Here's a small example of how I use it.


lparameter cDir, aDirs
local lFound, nNum, aList[1]

lFound = .F.
nNum = 0

with thisform
&&check for directory
if directory(cDir)
nNum = adir(aList, alltr(cDir)+ '*', 'D')
&&investigate each file or directory in search directory
for x = 1 to nNum
&&if the object is a valid directory
if !(aList[x,1] == '.') and !(aList[x,1] == '..') ;
and 'D' $ aList[x,5]
&&add it to the array
if alen(aDirs) = 1
aDirs[alen(aDirs)] = aList[x,1]
else
dimen aDirs[alen(aDirs) +1]
aDirs[alen(aDirs)] = aList[x,1]
endif
endif
endfor
endif
endwith

 
Hi CFB,
**********************************************************
oMyFiler = CREATEOBJECT('Filer.FileUtil')
oMyFiler.SearchPath = 'C:\VFP98' && Search Directory
oMyFiler.SubFolder = 1
oMyFiler.Find(1) && search and cumulate sub-folders
LOCAL nCount
nCount = 1
clear
FOR nFileCount = 1 TO oMyFiler.Files.Count
? nFileCount, oMyFiler.Files.Item(nFileCount).path + ;
oMyFiler.Files.Item(nFileCount).Name, ;
oMyFiler.Files.Item(nFileCount).Size
IF nCount > 20
nCount = 1
WAIT
ELSE
nCount=nCount+1
ENDIF
ENDFOR
*********************************************************
Hope this idea helps ramani :-9
(Subramanian.G)
FoxAcc
ramani_g@yahoo.com
LET KNOW IF THIS HELPED. ENOUGH EXPERTS ARE HERE TO HELP YOU OUT! BEST OF LUCK :)
 
Thanks for all the help folks. I haven't tried using the Filer object before, but plan to test it out since it seems to cut about 10 lines of code out of my current function. Right now I have a recursive function that walks through all the directories in a set path. The code I posted was a snippet of what I'm using now. Currently I'm using a function in my application that depending on how you call it can return combined file size, number of subdirectories, number of files, and an array of the subdirectories. Anyhow, thanks again everyone for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top