List the files in a folder
Author: bignonj@gmail.com (Bignon)
Hello there,
I'd list the files xml in a folder and loop over to the last...
How do I do this in Uniface 7206 ?
I've the idea of releasing a list with a batch dos and take this list in Uniface to start the loop..
Thanks a lot,
Jérôme
8 Comments
Local Administrator
Hi Jérôme,
the DOS command file is an option,
But if you are willing to invest a bit more time, I would recommend a little DLL.
Success, Uli
I used the following
#include <windows.h>
#include <dos.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
/* **************************** Global Variables */
char SI1[8001]; /* Input1 Stringbuffer 8K */
char SO[8001]; /* Output Stringbuffer 8K */
XEXPORT(long) um_showtree(void)
{ /* show all files under directory (path in $35) */
long retval;
all_clr();
UGETREGS(35,SI1,sizeof(SI1)-1); /* Filename */
strcpy(SO,"um_showtree starts from: ");
strcat(SO,SI1);
strcat(SO,"\n");
retval = (long) dirscan(SI1,1);
UPUTREGS(30,SO);
return(retval);
}
/* ********************************** Internal Routines ****************** */
int dirscan(char *pattern,int dmode)
{
struct _find_t c_file;
unsigned attrib;
int done, return1;
char fullname[_MAX_PATH];
char a[_MAX_PATH];
char b[_MAX_PATH];
if (pattern[0] == 0)
{
strcat(strcpy(SO,"Illegal pattern: "),pattern);
return(-2);
};
make_path(pattern,a);
if (get_fileattr(a,&attrib) != 0)
{
strcat(strcpy(SO,"No file access: "),pattern);
return(-5);
};
if ((attrib & _A_SUBDIR) == 0)
{
strcat(strcpy(SO,"Path not a directory: "),pattern);
return(-6);
};
done = _dos_findfirst(strcat(strcpy(b,a),"\\*.*"), _A_SUBDIR, &c_file );
while (!done)
{
if ( (strcmp(c_file.name,"..") != 0)
&&(strcmp(c_file.name,".") != 0) )
{
strcat(strcat(strcpy(fullname,a),"\\"),c_file.name);
if ((c_file.attrib & (_A_SUBDIR) ) != 0)
{
if (dmode == 1)
{
strcat(strcat(strcat(SO,"DIR:"),fullname),"\n");
}
if ((return1 = dirscan(fullname,dmode)) != 0)
return(return1);
if (dmode == 2)
{
if (_rmdir(fullname) != 0)
{
strcat(strcpy(SO,"Error removing dir: "),fullname);
err_str();
return(-3);
};
}
}
else
{
if (dmode == 1)
{
strcat(strcat(strcat(SO,"---:"),fullname),"\n");
}
if (dmode == 2)
{
if (remove(fullname) != 0)
{
strcat(strcpy(SO,"Error removing file: "),fullname);
err_str();
return(-4);
};
}
}
}
done = _dos_findnext( &c_file );
}
return(0);
}
Author: ulrich-merkel (ulrichmerkel@web.de)
Local Administrator
thanks Ulrich, i'll try it...
Author: Bignon (bignonj@gmail.com)
Local Administrator
also use this dll, I must :
- Create a file dll with this code inside,
- Put the dll in the Bin folder ( with others dll),
- Make a signature with operations,
- and call it from Uniface..
Ok I'll go over there...
Author: Bignon (bignonj@gmail.com)
Local Administrator
Hi Jerome,
no need for signature, it uses $registers for data exchange: getregs, putregs.
$35 = "C:\mydir" ; provide a search template
perform "um_showtree" ; just keep it going
my_list = $30
You can place the DLL next to the application with an INI assignment (ASN in Uniface8+):
[userdlls]
;path=..\3gl
demandload=MY123.dll,another.dll
Give me 2 days to prepare a Uniface 7.2.06 prototype package plus docu for you.
Anything else i can add for you to the package?
Like reading a flat file line by line, the famous USEQREAD?
Success, Uli
Author: ulrich-merkel (ulrichmerkel@web.de)
Local Administrator
Hi Jerome,
another option which is already available in Uniface 7 is the interrupt statement.
You find it documented at $UUU http://march-hare.com/puuu/undoc/interrupt.html
Interruptcodes 10 will list files, interruptcode 11 subdirectories of a given mask.
file_mask = "C:\mydirectory\*.xml" ; can be relative to the workingdirectory
interrupt(10,file_mask)
list_of_files = $result
delitem list_of_files,1 ; the first is the file_mask
Perhaps this suits your needs.
From Version 8 onwards, you can use the function $ldirlist:
variables
string vFilePath, vContent
numeric N
endvariables
$dir$ = "drinks\tea"
vContent = $ldirlist($dir$,"File")
putmess "Files in directory '%%$dir$':"
N = 1
getitem vFilePath, vContent, N
while ($status > 0)
putmess " %%vFilePath%%%"
N = N + 1
getitem vFilePath, vContent, N
endwhile
end
Success, Uli
Author: ulrich-merkel (ulrichmerkel@web.de)
Local Administrator
ok it's good Ulrich, I'll just do : dir /b /a-d > toto.txt.
Put this code in a bat file before running a startup Shell.
Thanks ( as usual) for your help, and your knowledge.
Author: Bignon (bignonj@gmail.com)
Local Administrator
Hi Jerome,
You know all of this is available in Uniface 9 :-)
Theo.
Author: Theo Neeskens (tneeskens@itblockz.nl)
Local Administrator
Hi Théo,
See that with my company ;-)
I'd love Uniface 9 !!
Jérôme
Author: Bignon (bignonj@gmail.com)