Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #11854

Re: Files in sub directories

From Arne Ortlinghaus <Arne.Ortlinghaus@acs.it>
Newsgroups comp.lang.clipper.visual-objects
Subject Re: Files in sub directories
Date 2018-08-30 15:38 +0200
Organization Aioe.org NNTP Server
Message-ID <pm8s0a$1m24$1@gioia.aioe.org> (permalink)
References <e850893c-980b-4e22-8d9e-bd39dd69ae09@googlegroups.com> <c2704b98-2090-4498-ad0b-9ecd07776bc4@googlegroups.com>

Show all headers | View raw


Hi Henry,
here is a function, that reads the directories into an array and that 
can already do recursive calling.

Arne



function Directory2ArrayEx( cFiles, uAttributes )
//p Zurückgabe von Dateien in ein Array (wie Directory)
//d Im Unterschied zu Directory2Array können mehrere Suchmöglichkeiten 
angegeben mit ; getrennt. \line
//d Als erstes Feld wird der volle Pfadname zurückgegeben und nicht nur 
der Dateiname/Extension \line
//d Directory funktioniert nicht, weil Directory nur die Dateien 
zurückgibt mit dem Archivebit gesetzt.
//d die Attribute für Übergabe sind etwas anders definiert.
//d Es werden automatisch die Directories . und .. ausgeblendet.
//d Struktur des Rückgabe-Arrays ist wie aus Funktion DIRECTORY()  \line
//d Zusätzlich wird noch nach dem Namen aufwärts sortiert
//d aDir[i,1]	Dateiname inklusive Pfad   \line
//d aDir[i,2]	Dateigroesse  \line
//d aDir[i,3]	Datum letztes Schreiben  \line
//d aDir[i,4]	Uhrzeit letztes Schreiben  \line
//d aDir[i,5]	Dateiattribute  \line
//d           Stringkombination aus folgenden Zeichen:  \line
//d           D				Directory  \line
//d				H				Hidden  \line
//d				S				System  \line
//a cFiles - String: kompletter Suchpfad mit * oder ?
//a uAttributes - Einschränkung der Suchkriterien (String oder nil)
//a               Standard ist "FD", Dateien und Directories
//a               Character	Beschreibung
//a               D				Directory
//a               F				Dateien
//a               R Rekursive eine Ebene höher, RR zwei, RRR drei, ... 

//a               andere Parameter werden ignoriert
//r Array: Feld unter Beschreibung
//g Files

local adirrrecursive, aSearch, aDir	as array
local pWin32_Find_Data	is _WINWIN32_FIND_DATA
local irec as dword
local SysTime			is _WINSYSTEMTIME
local hSearch			as ptr
local dFileDate			as date
local cDir, cFileTime			as string
local cFileName as string
local dwAttributes as dword
local cts, cSearch, cAttributes as string
local lrecursive, lSearchDir as logic
local lSearchFiles as logic
local h,m,s as int
local ftlocaltime is _WINFILETIME
local f as real8
local i as dword

Default (@uAttributes, "FD")
aDir := {} // Rückgabe-Array, das letzte Element mit den Dateiattributen 
bleibt vorerst leer, wir brauchen es bisher nicht!
aSearch := String2Array(cFiles, ";")
lSearchDir := false
lSearchFiles := false
lrecursive:= false

if IsString(uAttributes)
	uAttributes := Upper(uAttributes)
	lSearchDir := InStr("D", uAttributes)
	lSearchFiles := InStr("F", uAttributes)
	lrecursive:= InStr("R", uAttributes)
	if lrecursive
	   uAttributes := substr(uAttributes, 1, slen(uAttributes)-1)
	endif
endif
for i := 1 upto ALen(aSearch)
    cSearch := aSearch[i]
    cDir := FAddBackslash(FGetDir(cSearch))
    hSearch := null_ptr
    MemSet(@pWin32_Find_Data, 0, dword(_sizeof(_WINWIN32_FIND_DATA))) 
//X# AO 11/2016
    do while iif ( hSearch == null_ptr, ;
    		(( hSearch := FindFirstFile(String2Psz(cSearch),@pWin32_Find_Data) 
) != null_ptr) ;
    			.and. !Empty(Psz2String(@pWin32_Find_Data.cFileName)),;
    		FindNextFile(hSearch,@pWin32_Find_Data);
    		)
    	cFileName := Psz2String(@pWin32_Find_Data.cFileName)
    	// Datum und Uhrzeit muessen wir noch rauskriegen, also erstmal 
konvertieren

    	//von UTC-Time nach lokaler Zeit
    	FileTimeToLocalFileTime(;
        @pWin32_Find_Data.ftLastWriteTime,	;// pointer to UTC file time 
to convert
        @ftlocaltime 	;// pointer to converted file time
       )
       //Zerlegen der Zeit
    	FileTimeToSystemTime(;					// Win-API!
        	@ftlocaltime,;	//
    	    @SysTime )
    	// Einzelwerte in VO-Datumsformat umwandeln
// Todo 100317 AO 2016-07-13 15:57 Vulcan: Umstellung, Fehlersuche, ...
//   	dFileDate := CToD( LTrim(Str3(systime.wday,2,0)) + "." + 
LTrim(Str3(systime.wmonth,2,0)) + "." + Str3(systime.wyear,4,0))
    dFileDate := makedate(systime.wyear, systime.wmonth, systime.wday)


    	h := systime.wHour
    	m := systime.wMinute
    	s := systime.wSecond
    	cFileTime := StrZero(h,2) + ":" + StrZero(m,2) + ":" + StrZero(s,2)

    	dwAttributes := pWin32_Find_Data.dwFileAttributes
    	cAttributes := ""
    	if _and (dwAttributes, FILE_ATTRIBUTE_DIRECTORY) != 0
    		cAttributes += "D"
    	endif
    	if _and (dwAttributes, FILE_ATTRIBUTE_HIDDEN) != 0
    		cAttributes += "H"
    	endif
    	if _and (dwAttributes, FILE_ATTRIBUTE_SYSTEM) != 0
    		cAttributes += "S"
    	endif
    	// Todo 104362 Job für nächtliche Kontrolle DB-Skript-Dateien und 
Setzen des "Readonly"-flags
    	if _and (dwAttributes, FILE_ATTRIBUTE_READONLY) != 0
    		cAttributes += "R"
    	endif


    	cFileName := AllTrim(cFileName)
    	if (lSearchDir .and. InStr("D", cAttributes) .and. 
!InList(cFileName, ".", ".."))
          f := pWin32_Find_Data.nFileSizeLow
          if pWin32_Find_Data.nFileSizeHigh > 0
             f += (1.0*pWin32_Find_Data.nFileSizeHigh)*MAXDWORD
          endif   			 

          // Todo 106250 AO 2017-05-30 15:46 Verbesserungen 
Standardfunktionalitäten 2017
          cts := substr(maketimestampbase(dfiledate), 1, 11)+cFileTime
    	    AAdd(aDir,{cDir + cFileName,;                 				// FileName
    					f,;			// FileSize
    					dFileDate,;
    					cFileTime,;
    					cAttributes, ;
    					cts})
          if lrecursive
             adirrrecursive := Directory2ArrayEx( cDir + 
cFileName+"\"+fgetfilenameandext(cFiles), uAttributes )
             for irec := 1 upto alen(adirrrecursive)
                AAdd (adir, adirrrecursive[irec])
             next
          endif   					
    	endif
    	if (lSearchFiles .and. !InStr("D", cAttributes))
          f := pWin32_Find_Data.nFileSizeLow
          if pWin32_Find_Data.nFileSizeHigh > 0
             f += (1.0*pWin32_Find_Data.nFileSizeHigh)*MAXDWORD
          endif
          // Todo 106250 AO 2017-05-30 15:46 Verbesserungen 
Standardfunktionalitäten 2017
          cts := substr(maketimestampbase(dfiledate), 1, 11)+cFileTime
    	    AAdd(aDir,{cDir + cFileName,;                 				// FileName
    					f,;			// FileSize
    					dFileDate,;
    					cFileTime,;
    					cAttributes, ;
    					cts})
    	endif

    enddo
    if hSearch != null_ptr
    	FindClose(hSearch)
    endif
next

ASortTwoDim (adir, 1, true)
return (aDir)

Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Files in sub directories fidlergad@gmail.com - 2018-08-29 04:08 -0700
  Re: Files in sub directories simon@abersoftware.co.uk - 2018-08-29 06:15 -0700
  Re: Files in sub directories fidlergad@gmail.com - 2018-08-29 08:47 -0700
    Re: Files in sub directories Arne Ortlinghaus <Arne.Ortlinghaus@acs.it> - 2018-08-30 15:38 +0200

csiph-web