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

Traversing Folders on Drive C with Adir()

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

Folders like "c:\users", "c:\windows", "c:\program files" are all being skipped in Windows 7/8 when running this code... I can traverse those folders in Windows explorer without issue...

Any idea what I can change?

Thanks,
Stanley


Code:
pcStartFolder = 'C:\'
lcPath = ''

Public gcExt, gcStartFolder, gcType, gcTypeName
gcStartFolder = pcStartFolder
gcTypeName = ''

Create Cursor FileList (file_name c(64), full_path c(254), file_type c(1), file_ext c(20), file_size I, type_name c(40))

If Empty(lcPath)
	lcPath = gcStartFolder
Endif

*-- Call the recursive routine to walk the tree...
Do treewalk With lcPath
Wait Clear

	**************************************************************************************
Procedure treewalk
	Parameters lcPath
	Private All Like l*
	Do Case
	Case Adir(laFileList,lcPath+"*.MP3") <> 0	&&MP3
			gcType="M"
			gcTypeName = 'MP3 Audio'
			gcExt="MP3"
			=storeit(@laFileList,lcPath)
	Endcase

	* Determines whether there are any subdirectories.
	lnDirCount = Adir(laSubDirs, lcPath + "*.*", "D")
	If lnDirCount > 0
		For lnCount = 1 To lnDirCount
			If (laSubDirs[lnCount, 5] = ".H..D" .or. laSubDirs[lnCount, 5] = "....D") .And. Left(laSubDirs[lnCount, 1], 1) # "."
				* If so, traverse them...
				Do treewalk With lcPath + laSubDirs[lnCount, 1] + "\"
			Endif
		Next
	Endif
Endproc


**************************************************************************************
*-- Store values into FileList.
Procedure storeit
	Parameters laFileList, lcPath
	Local lcBarePath, lcDrive
	lcDrive = Left(lcPath, 1)
	lcBarePath = Substr(lcPath, 3, 158)
	Wait Window Nowait "Processing Folder: " + lcPath

	If Type("laFileList[1]") #"U" And !Empty(laFileList[1])
		For lnCount = 1 To Alen(laFileList, 1)
			gcExt = Justext(Alltrim(lcDrive) + ":" + lcBarePath + Alltrim(laFileList[lnCount, 1]))

			Wait Alltrim(lcDrive)+":"+lcBarePath+Alltrim(laFileList[lnCount,1]) Window Nowait

			Insert Into FileList (file_name, full_path, file_type, file_ext, file_size, type_name) ;
				VALUES (;
				laFileList[lnCount, 1], ;
				alltrim(lcDrive) + ":" + lcBarePath + Alltrim(laFileList[lnCount, 1]), ;
				gcType, ;
				gcExt, ;
				laFileList[lnCount, 2], ;
				gcTypeName)
		Next
	Endif
Endproc
 
Folders like "c:\users", "c:\windows", "c:\program files" are all being skipped in Windows 7/8 when running this code...

They're probably hidden or protected. (They *should* be!)

Have you checked into the various flags available for Adir() to "see" hidden folders?
 
ADIR(ArrayName [, cFileSkeleton [, cAttribute [, nFlag]]])


Letter Attribute
A Archive – Read/Write

H Hidden

R Read-only

S System

D Directory




Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Code:
CLEAR
i = ADIR(test,"c:\*.*","shd")
FOR x = 1 TO i
	? test[x,1],test[x,5]
next

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are not good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top