ANSI Standard PL/B Language and Visual PL/B
NOTE TO OUR READERS
This web resource is written for our own use. But we feel strongly that the PL/B language should be shared with the software community. So feel free to use this at will!
BUT PLEASE...
if you find errors or omissions or have a better way to do something. TELL US! Dialog helps us all. Send e-mail to:
support@mmcctech.com
FINDFILE:
-
This is a SUNBELT ONLY language feature.
CONCEPT OF USE
The FINDFILE instruction provides a fast way of gathering information about a fail such as the size, path, date updated, and attributes.
This is a very simple instruction. You just code
FINDFILE {filename}, FILESIZE=xxxx and the information is returned.
The file does not have to be opened.
Wild cards are accepted in the file name.
There's a general routine in the
MMCCSERV.PLS include unit and there are work fields defined in
COMMONWK.PLS as follows:
COMMONWK.PLS fields:
$FF_NAME DIM 250 ;pass this name in or clear yourself
$FF_DATA LIST
$FF_ERROR DIM 5
$FF_SIZE FORM 10
$FF_TIMESTAMP DIM 18
$FF_ALTNAME DIM 250
$FF_ATTRIBUTES INTEGER 4
$FF_PATH DIM 250
$FF_ALTPATH DIM 250
LISTEND
MMCCSERV.PLS routine:
find_file ROUTINE $FF_NAME
DISPLAY *COLOR COL$10,*EL:
"MMCCSERV:find file ",*HON,*LL,$FF_NAME,*HOFF:
*COLOR COL$POP
UNPACK NUL, $FF_DATA ;all but $FF_NAME
FINDFILE $FF_NAME:
FILESIZE=$FF_SIZE:
WRITE=$FF_TIMESTAMP:
NAME=$FF_NAME:
ALTNAME=$FF_ALTNAME:
ATTRIBUTES=$FF_ATTRIBUTES:
PATH=$FF_PATH:
ALTPATH=$FF_ALTPATH
IF NOT ZERO
MOVE "FAIL",$FF_ERROR
ENDIF
RETURN
NOTES
FINDFILE requires the
FULL PATH and NAME for the file.
If you have just opened the file and want to use FINDFILE to get stuff line the date and size, you'll need to get the path another way. For that you can use
GETFILE with the
TXTNAME property. This is the full name and path.
...........................
. Example
.
MYFILE FILE
FILENAME DIM 250
OPEN MYFILE, "ZZDATA"
GETFILE MYFILE, TXTNAME=FILENAME
IF ZERO
DISPLAY "File name is ",*HON,*LL,FILENAME,*PL,*HOFF
ELSE
DISPLAY "File is NOT OPEN"
ENDIF
See
GETFILE in the FILE HANDLING NOTES report.
FINDDIR
From a discussion on the Sunbelt Forum 4/20/2011
From Gerhard Weiss BeneSys, Inc
FINDDIR is nice. I used it once.
In another post I wrote that I want to use COPYFILE with wildcards. This
is not available and instead FINDDIR needs to be used to get the
filename and then build a COPYFILE command for each file.
The only limitation, I see, is you have to know how big the FINDDIR
Destination String needs to be.
Is there a way to calculate this size?
I am also thinking DMAKE should be used to create the Destination
String. This way the variable can be created and freed so it is not taking
up that much memory when it is done.
I no one ever used the FINDDIR before, here is the code I wrote a few
months back that returns directory names for pattern F:\CLS*.
CLSPAT INIT "F:\CLS*"
CLSALLDIR DIM ^3000
CLSALLIN FORM 2
CLSALLLS FORM 2
CLSALLMX CONST "30"
CLSALLTB DIM 20(CLSALLMX)
CLSEXIST DIM 1(CLSALLMX)
FINDDIR CLSPAT,CLSALLDIR,MODE=4,ITEMCOUNT=CLSALLLS
EXPLODE CLSALLDIR,"|",CLSALLTB
FOR CLSALLIN FROM "1" TO CLSALLLS
SDELETE CLSALLTB(CLSALLIN),N1
MOVE "F:\",D3
SINSERT CLSALLTB(CLSALLIN),D3
RESET CLSALLTB(CLSALLIN)
.
DISPLAY "FINDDIR ",CLSALLTB(CLSALLIN)
REPEAT
.
.... If run today, it would return these directories on our system:
F:\CLS
F:\CLS_20110131
F:\CLS_20110228
F:\CLS_20110331
From Stuart Elliott CenterStone, Inc
This is what I do all the time:
sFNlist dim ^100
filename dim 260
filename1 dim 260
filename2 dim 260
nwork12 form 12
pack filename with "c:\data\*.*"
move n0 to nwork12
loop
add "100" to nwork12 // make it bigger
dfree sFNlist // reset DIM
dmake sFNlist,nwork12 // make the target DIM
finddir filename to sFNlist,mode=2
repeat while ( eos ) // target DIM not big enough; try again
Then, to process the filename list:
loop
explode sFNlist by "|" into filename
fsave
splice "",filename,1 // remove leading 'f'
pack filename1 with "c:\data\",filename
pack filename2 with "\\server\folder\",filename
copyfile filename1,filename2
frestore
repeat until ( zero )
From R. Leidy Norman, Oklahoma
This alternative has it's own pros and cons, but the old datalist object has a method named Dir.
You can use wildcards in the *fileSpec= parameter, and some other options in the *flags= parameter.
The benefit is you don't have to pre-allocate memory/dim for the result, every file will just be another line in the datalist.
plb-0350 v1.20