----------------------------------------------------------------------
--- Knud van Eeden --- 05 December 2009 - 10:13 pm -------------------

Computer: Editor: Text: TSE: Directory: File: All: Operation: Get: How to get all filenames in a given directory and its subdirectories? [recursive walk the tree]

===

Steps: Overview:

 1. -E.g. create the following program:

--- cut here: begin --------------------------------------------------
// filenamemacro=getfittr.s
--- cut here: end ---------------------------------------------------- --- cut here: begin --------------------------------------------------
// PROC PROCFileGetAllDirectoryWalkTheTree( STRING directoryS )
--- cut here: end ---------------------------------------------------- --- cut here: begin --------------------------------------------------
FORWARD PROC Main() FORWARD PROC PROCFileGetAllDirectoryWalkTheTree( STRING s1 ) FORWARD PROC PROCFileGetAllDirectoryWalkTheTreeSub( STRING s1, INTEGER i1 ) // --- MAIN --- // PROC Main() STRING s1[255] = "" IF ( ( Ask( "file: get: all: directory: walk: the: tree: directoryS = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) PROCFileGetAllDirectoryWalkTheTree( s1 ) ENDIF END <F12> Main() // --- LIBRARY --- // // library: file: get: all: directory: walk: the: tree <description></description> <version control></version control> <version>1.0.0.0.24</version> (filenamemacro=getfittr.s) [kn, ri, sa, 05-12-2009 21:19:56] PROC PROCFileGetAllDirectoryWalkTheTree( STRING directoryS ) // e.g. PROC Main() // e.g. STRING s1[255] = "" // e.g. IF ( ( Ask( "file: get: all: directory: walk: the: tree: directoryS = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) // e.g. PROCFileGetAllDirectoryWalkTheTree( s1 ) // e.g. ENDIF // e.g. END // e.g. // e.g. <F12> Main() // INTEGER bufferI = 0 // PushPosition() bufferI = CreateTempBuffer() PopPosition() // PROCFileGetAllDirectoryWalkTheTreeSub( directoryS, bufferI ) // GotoBufferId( bufferI ) // END // library: file: get: all: directory: walk: the: tree: sub <description></description> <version control></version control> <version>1.0.0.0.0</version> (filenamemacro=getfitsu.s) [kn, ri, sa, 05-12-2009 21:22:40] PROC PROCFileGetAllDirectoryWalkTheTreeSub( STRING directoryS, INTEGER bufferI ) // e.g. PROC Main() // e.g. PROCFileGetAllDirectoryWalkTheTreeSub( "c:\temp\ddd1", CreateTempBuffer() ) // e.g. END // e.g. // e.g. <F12> Main() // INTEGER searchHandleI = FindFirstFile( Format( AddTrailingSlash( directoryS ), "*.*" ), -1 ) // STRING ffNameS[255] = "" // INTEGER directoryB = FALSE // // recursive stop // IF ( NOT ( searchHandleI == -1 ) ) // REPEAT // ffNameS = FFName() // directoryB = FALSE // IF ( FFAttribute() & _DIRECTORY_ ) // directoryB = TRUE // IF ( NOT ( ffNameS == "." ) AND ( NOT ( ffNameS == ".." ) ) ) // // recursive call // PROCFileGetAllDirectoryWalkTheTreeSub( Format( AddTrailingSlash( directoryS ), ffNameS ), bufferI ) // ENDIF // ENDIF // // only include filenames here (and do by design not include directories) // IF ( NOT ( directoryB ) ) // // do something // AddLine( Format( FFSize():-10, FFDateStr():-15, FFTimeStr():-10, directoryS:-50, ffNameS:-120 ), bufferI ) // ENDIF // UNTIL ( NOT ( FindNextFile( searchHandleI, -1 ) ) ) // FindFileClose( searchHandleI ) // ENDIF // END
--- cut here: end ---------------------------------------------------- 2. -Run the program 3. -Input a directory name (if it is a large directory, it will take some time (minutes) before you see any result) 1. -E.g. c:\log\ 4. -That will show a screen output similar to the following: --- cut here: begin --------------------------------------------------
74383103 05/12/2009 11:23:54 c:\log\subdirectory1\ ddd1.log 84383603 05/12/2009 11:23:54 c:\log\subdirectory2\ ddd2.log 84323603 05/12/2009 11:23:54 c:\log\subdirectory3\ ddd3.log 173312 05/12/2009 14:47:10 c:\log\ ddd4.log 177161 05/12/2009 14:52:14 c:\log\ ddd5.log 162921 05/12/2009 14:52:50 c:\log\ ddd6.log 111231 05/12/2009 14:53:02 c:\log\ ddd7.log 141621 05/12/2009 14:54:24 c:\log\ ddd8.log 180031 05/12/2009 14:55:10 c:\log\ ddd9.log 130041 05/12/2009 14:55:52 c:\log\ ddd10.log
--- cut here: end ---------------------------------------------------- === Book: see also: === Diagram: see also: === File: see also: === File: version: control: see also: === Help: see also: === Image: see also: === Internet: see also: --- Computer: Editor: Text: TSE: Directory: File: Directory: All: Operation: Get: Walk: The: Tree: Link: Can you give an overview of links? http://goo.gl/Iv38p === Podcast: see also: === Record: see also: === Screencast: see also: === Table: see also: === Video: see also: === <version>1.0.0.0.3</version> ----------------------------------------------------------------------

Share |

This web page is created and maintained using the Semware TSE text editor