Novelle


hi there!

im new to vfp and i want to make a programm that reads a certain directory and which gives me back the number of the files in that directory and the filenames.

can someone tell me how it works in vfp it will really be great... thanks in advanced!

novelle




Re: reading a directory for a existing files

Stuart Dunkeld


You can use ADIR to put the filenames into an array:

local cDirectory, arrFiles[1]
cDirectory = "c:\temp\"

nFiles = adir(arrFiles, cDirectory + "*.*")
for nCount = 1 to nFiles
    arrFiles[nCount, 1]
next






Re: reading a directory for a existing files

Novelle

i've tried it but it seems that is not working... i have vfp 7.0 so with that code i get the number of the files in the directory how can i get then filename

thanks a lot its really a big help!

novelle






Re: reading a directory for a existing files


Re: reading a directory for a existing files

Alex Feldstein

The ADIR() function gives you the information you need.

If you look at the help file here you see that the return value is the number of files foundthat match your specs. Element 1 of the array contains the filename you seek. Follow the example in the help page and you'll get it easily.





Re: reading a directory for a existing files

Novelle

hi thanks again...

what i really like to do is like this

i=0;

WHILE i NOT EQUAL numbersOfFiles in the directory THEN DO

DELETE FROM tabelle_1 WHERE nr IN(SELECT nr FROM this file in the directory)

NEXT

i want to check if this Nr. already exist on those files in the directory and if it exist there i want to delete it to my Tabelle_1

do u get me thanks in advanced!!!

novelle





Re: reading a directory for a existing files

Alex Feldstein

When you say:

>DELETE FROM tabelle_1 WHERE nr IN(SELECT nr FROM this file in the directory)

do you mean that nr is part of the filename or text inside the contents of the file





Re: reading a directory for a existing files

Novelle

yes its a column in both tables, i mean in table_1 and all the files i want to look in the directory...





Re: reading a directory for a existing files

SharathMum


nNoofFile = ADIR( aFile, "C:\Temp\*.*")

FOR i = 1 TO nNoOfFile
INSERT INTO tableDirFile ( nr ) VALUES ( aFile[i,1] )
NEXT

DELETE FROM tabelle_1 WHERE nr IN ( SELECT nr FROM tableDirFile )








Re: reading a directory for a existing files

CetinBasoz

You can use filer that comes with VFP. ie:

lcStartDir = HOME()
*lnFiles = GetTree(lcStartDir,'*.dbf;*.cdx;*.fpt', 'myCursor', .t.)
lnFiles = GetTree(lcStartDir,'*.*', 'myCursor', .t.)
Local array arrSizeTot[1]
Select sum(FileSize) from myCursor into array arrSizeTot
  trans(iif(_Tally>0,arrSizeTot,0))+' bytes in '+trans(m.lnFiles)+' files.'

Select * ;
	from myCursor ;
	order by filepath, Isfolder desc, Filename

Function GetTree
Lparameters tcStartDir,tcSkeleton,tcCursorName,;
 tlSubfolders,;
 tlWholeWords,tlIgnoreCase,tlSearchAnd,tcSearch1,tcSearch2,tcSearch3
Create Cursor (tcCursorName) ;
 (filepath c(250), filename c(250), ;
 FileSize i, fattr c(8), createtime T, lastacc T, lastwrite T, IsFolder l)
Local oFiler, lnFound
oFiler = Createobject('filer.fileutil')
With oFiler
 .SearchPath = tcStartDir
 .FileExpression = tcSkeleton && Search for skeleton
 .Subfolder  = iif(tlSubfolders,1,0) && Check subfolders
 .IgnoreCase = iif(tlIgnoreCase,1,0)
 .WholeWords = iif(tlWholeWords,1,0)
 .SearchAnd  = iif(tlSearchAnd,1,0)
 .SearchText1 = iif(empty(tcSearch1),"",tcSearch1)
 .SearchText2 = iif(empty(tcSearch2),"",tcSearch2)
 .SearchText3 = iif(empty(tcSearch3),"",tcSearch3)
 lnFound = .Find(0)
 For ix=1 To lnFound
  With .Files(ix)
   If !(Bittest(.Attr,4) And .Name = '.')
    Insert Into (tcCursorName) ;
     (filepath, filename, FileSize, fattr, createtime, lastacc, lastwrite,IsFolder) ;
     values ;
     (.Path, .Name, .Size, Attr2Char(.Attr), ;
     Num2Time(.Datetime), Num2Time(.LastAccessTime), Num2Time(.LastWriteTime),Bittest(.Attr,4))
    IF Bittest(.Attr,4)
	    WAIT WINDOW NOWAIT "Folder: "+.Path
    endif
   Endif
  Endwith
 Endfor
ENDWITH
WAIT clear
Return lnFound

Function Num2Time
Lparameters tnFloat
Return Dtot({^1899/12/30}+Int(tnFloat))+86400*(tnFloat-Int(tnFloat))

Function Attr2Char
Lparameters tnAttr
Return ;
 IIF(Bittest(tnAttr,0),'RO','RW')+;
 IIF(Bittest(tnAttr,1),'H','_')+;
 IIF(Bittest(tnAttr,2),'S','_')+;
 IIF(Bittest(tnAttr,4),'D','_')+;
 IIF(Bittest(tnAttr,5),'A','_')+;
 IIF(Bittest(tnAttr,6),'E','_')+;
 IIF(Bittest(tnAttr,7),'N','_')




Re: reading a directory for a existing files

Novelle

hi guys!

thank u really for ur replies but i think u misunderstood me with this problem, ok...

in vfp 7.0 let say when i have 2 tables (i mean by that files with *.DBF) let say i opened the table_1 and want to delete all data in table_1 which already exists in table_2, so i can do something like this...

DELETE FROM table_1 WHERE nr IN(SELECT nr FROM table_2)

PACK

and in this case i dont only have table_2 but also alot of tables let say till table_n

thats why i want to do something like this....

i=0

while i not equal the number of files in my desired directory then

delete from table_1 where nr in(select nr from the first file in the directory) (so if i have 3 files i want to change it automaticly from the next file in the directory...)

NEXT

PACK

i hope i explained it clearly, any help and suggestions will be appriciated! thanks a lot!!

novelle





Re: reading a directory for a existing files

Lakshmi N

first get the list of files from your directory into a dbf/cursor

  • crea table xxx ;
    • (tblnm c(8),delflag c(1)) && create a temp table to store table names and flag to store whether to be deleted or not
  • sele b
  • use xxx shared alias xxx &&open that dbf
  • DIMENSION TEMPARRAY(1,5) && declare array to store table names
  • =ADIR(TEMPARRAY,"c:\temp\*.*") &&use adir to get table names into array
  • X = ALEN(TEMPARRAY,1) &&find the length of array
  • FOR I = 1 TO X &&in a for loop put table names into xxx.dbf (temp table created earlier)
    • sele xxx
    • appe blank
    • repl tblnm with temparray(i,1)
  • NEXT I

now check if column nr exists in a table and if exists repl delflag with 'Y'

  • flnm = " " &&start from table xxx
  • sele xxx
  • go top
  • do while !eof() &&loop through xxx to replace delflag
    • flnm = allt(xxx.tblnm)
    • sele c
    • use &flnm excl alias tblone
    • for i = 1 to fcount()
    • if field(mcount) = "NR"
      • sele xxx
      • repl delflag with 'Y'
    • next
    • sele c
    • use
  • sele xxx
  • if !eof()
    • skip
    • endif
  • enddo

now loop through xxx to find if delflag = "Y" and if yes delete that file

  • delfl = " " &&delfl is a variable which holds file name to be deleted
  • sele xxx &&loop through xxx.dbf
  • go top
  • do while !eof()
  • delfl = allt(xxx.tblnm) &&assign filename to delfl
  • if delflag = 'Y'
    • !del &delfl
  • endif






Re: reading a directory for a existing files

Novelle

SharathMum wrote:

nNoofFile = ADIR( aFile, "C:\Temp\*.*")

FOR i = 1 TO nNoOfFile
INSERT INTO tableDirFile ( nr ) VALUES ( aFile[i,1] )
NEXT

DELETE FROM tabelle_1 WHERE nr IN ( SELECT nr FROM tableDirFile )

this is good it gives me how many files in the directory so what i want to know now how do i get the names of the DBF files without its extension .DBF and select the names one by one or save in a current variable let say x:=this.current.filename

example let say i have 3 DBF files in the directory

i:=0; && number of files in the directory, undefined at the moment

x:= nil; && undefined at the moment

while i != nNoofFile then

x:=get.the.first.filename.without.the.fileextension in the directory

delete from table_1 where nr in(select nr from + x +)

x:=get.the.second.filename.without.the.fileextension in the directory

end

pack

do u get me thanks a lot for ur reply...

novelle





Re: reading a directory for a existing files

Lakshmi N

first get the list of files from your directory into a dbf/cursor

  • crea table xxx ;
    • (tblnm c(8)) && create a temp table to store table names
  • sele b
  • use xxx shared alias xxx &&open that dbf
  • DIMENSION TEMPARRAY(1,5) && declare array to store table names
  • =ADIR(TEMPARRAY,"c:\temp\*.dbf") &&use adir to get table names into array
  • X = ALEN(TEMPARRAY,1) &&find the length of array
  • FOR I = 1 TO X &&in a for loop put table names into xxx.dbf (temp table created earlier)
    • sele xxx
    • appe blank
    • repl tblnm with temparray(i,1)
  • NEXT I

now u use xxx table to loop through and delete records in table1 which is found in table2,table3 and so son

  • firstfl = "abc.dbf " &&variable which holds first table name where data needs to be deleted
  • subfl = "" &&variable which holds subsequent table names
  • sele xxx &&select the table which holds table names
  • dele for tblnm = 'abc' &&since your base table from which data to be deleted also in xxx so delete from xxx
  • go top &&go to top of file
  • sele b
  • use &firstfl excl alias firstfl &&open the base table from which data needs to be deleted
  • sele xxx
  • do while !eof() &&loop through xxx table
    • subfl = allt(xxx.tblnm) &&store the subsequent file names
    • sele c
    • use &subfl excl alias subfl &&use the subsequent file
    • sele b
    • delete from firstfl where nr in(select nr from subfl) &&delete from base table where data is found in subsequent tables
    • sele c
    • use
    • sele xxx
    • if !eof()
    • skip
    • endif
  • enddo

regards






Re: reading a directory for a existing files

Novelle

sorry but this really very complicated....