Hello,
The function "Directory()" reads the names and data of the files in a certain folder.
But how can we read the names of all the folders which can be found in a certain folder.
Thank you very much in advance.
/*
Purpose: Get list of folders (directories)
Author : James Bott, jbott@compuserve.com
Syntax : getFolders( <cPath> )
cPath defaults to current directory
Returns: Array of directory names, or empty array if no directories exist
Bug : A filename with no extension will be
included as a directory even though it is not.
*/
#include "fivewin.ch"
//--- Test only
function main()
local aFolders:= getFolders( "c:\" )
local cString:= ""
local i:=0
for i=1 to len( aFolders )
cString := cString + aFolders[i] + chr(10)
next
msgInfo( cString )
return nil
//--- end test
function getFolders( cPath )
local aFiles := {}
local aFolders:={}
local i:=0
default cPath:= ""
cPath:= if( right(cPath,1)="\", cPath + "*.", cPath + "\*." )
aFiles := directory( cPath, 'D' )
// We start at 3 to eliminate the always present "." and ".." directories
for i=3 to len(aFiles)
aadd( aFolders, aFiles[i,1] )
next
return aFolders
// EOF
#include "fivewin.ch"
//--- Test only
function main()
local aFolders:= getFolders( "c:\" )
local cString:= ""
local i:=0
for i=1 to len( aFolders )
cString := cString + aFolders[i] + chr(10)
next
msgInfo( cString )
return nil
//--- end test
function getFolders( cPath )
local aFiles := {}
local aFolders:={}
local i:=0
local cOldPath := cPath // Added by RAMESH BABU P
default cPath:= ""
cPath:= if( right(cPath,1)="\", cPath + "*.", cPath + "\*." )
aFiles := directory( cPath, 'D' )
// We start at 3 to eliminate the always present "." and ".." directories
for i=3 to len(aFiles)
if IsDirectory(cOldPath+"\"+aFiles[i,1]) // Added by RAMESH BABU P
aadd( aFolders, aFiles[i,1] )
endif
next
return aFolders
// EOF
/*
Purpose: Get list of folders (directories)
Author : James Bott, jbott@compuserve.com
Syntax : getFolders( <cPath> )
cPath defaults to current directory
Returns: Array of directory names, or empty array if no directories exist
Note: Thanks Ramesh for the bug fix!
*/
#include "fivewin.ch"
//--- Test only
function main()
local aFolders:= getFolders( "c:\downloads" )
local cString:= ""
local i:=0
for i=1 to len( aFolders )
cString := cString + aFolders[i] + chr(10)
next
msgInfo( cString )
return nil
//--- end test
function getFolders( cPath )
local aFiles := {}
local aFolders:={}
local i:=0
default cPath:= ""
cPath:= if( right(cPath,1)="\", cPath , cPath + "\" )
aFiles := directory( cPath + "*.", 'D' )
// We start at 3 to eliminate the always
// present "." and ".." directories
for i=3 to len(aFiles)
if IsDirectory(cPath + aFiles[i,1]) // Added by RAMESH BABU P
aadd( aFolders, aFiles[i,1] )
endif
next
return aFolders
// EOF
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 138 guests