Ilansu
3rd March 2003, 17:09
Hi all.
I need to scan a directory in order to update Baan table from the files in that directory.
After reading a file I'll need to delete it.
I knew the directory name but the files inside are unknown.
On the server side we can use the dir.entry() to get the directory content .
Is there any thing similar on the client side?
Thanks
Ilan S
lbencic
3rd March 2003, 21:56
You might check the dllbw library for some undocumented functions on the client side. I don't see an entry for a directory, but you can probably run a directory command to a file (using app_start), then use the seq.open.local to read through the file, then the remove.local.file command to delete the files.
This post has info on how to use that library:
http://www.baanboard.com/baanboard/showthread.php?s=&threadid=6641&highlight=odllbw
Ilansu
4th March 2003, 14:51
lbencic Hi.
The problem is as I mentioned that I don't know the files names.
I need to scan a specific directory and process all the files I find there.
I can run a VB program that will give me a file with the list of all files in that directory and then I can use the seq.open.local() to process the file.
I was looking for that functionality in Baan .
Thanks
Ilan S
lbencic
4th March 2003, 18:24
I know it's the long way, but: Try using the app_start command to issue a dir command to print the directory contents to a file. I did this long ago using server commands, I remember but don't have the code. Options on the directory command will set it to just give you file names. Direct the output of the dir command to a file and you can use the seq.open.local and read's to parse thru the file to get the file names.
Hope you find a quicker solution, but that should work.
Also, have a look at this post to see if it is of any use:
http://www.baanboard.com/baanboard/showthread.php?s=&threadid=1844&highlight=Explorer
NPRao
17th June 2003, 04:34
As Lisa said you can try to use the app_start() BaaN Commands to invoke the DOS commands with parameters -
C:\> dir C:\baandocs/s/b/a-d > np
C:\> dir [directory-name]:\[file-name] /s/b/a-d > [output-filename]
That will give you the list of all the files in that given path/directory and not subdirectories under the directory.
To get only directories use option: /ad
To get all directories and subdirectories just skip the option with "/a".
gget79
3rd December 2014, 21:52
Hi friends,
I have a source code that can help you, in resumen:
1. I read the directory in side cliente, I write file with dir command results.
2. With the file, I send file by file to server side
4. I write new file without CDATA XML Section
5. I read the files, and I process this files into BaaN
6. I move the file, to other site on client.
|****************************** declaration section ***************************
declaration:
table ttccom000 |
table ttcmcs010 | Países
extern domain tcncmp ncmp.f
extern domain tcncmp ncmp.t
#pragma used dll ottdllbw
|****************************** form section **********************************
|****************************** choice section ********************************
choice.cont.process:
| on.choice:
| read.main.table()
|****************************** field section *********************************
field.ncmp.f:
when.field.changes:
ncmp.t = ncmp.f
|****************************** function section ******************************
functions:
function extern procesar()
{
|Variables lectura de archivos en directorio servidor
extern long fd, counter, rt, size, mode, fp, fp1, sp
extern string fname(80), fpath(256), record(256), NameFile(256)
|Variables lectura de archivos en cliente
extern string local.dir(256)
|Proceso de lectura de archivos en cliente y graba el listado en archivo temporal cliente C:\trash\get\filenames.txt",
local.dir = "C:\trash\get"
| app_start("cmd /c dir *.xml /b "&strip$(local.dir)&" > C:\trash\get\filenames.txt", strip$(local.dir), "", "", "")
app_start("cmd /c dir "&strip$(local.dir)&"\*.xml /b > C:\trash\get\filenames.txt", strip$(local.dir), "", "", "")
|Pasar listado (C:\trash\get\filenames.txt") a una ruta en el cliente
|Abro Archivo
client2server("C:\trash\get\filenames.txt", "/export/home/get/test/cpx/get.txt", false, false)
fp1 = seq.open("/export/home/get/test/cpx/get.txt","r")
|Valido si hubo erro
if fp1 >= 1 then
|comienzo a leer los archivos
while seq.gets(record,2048,fp1) = 0
|Separo en registros la cadena del string
if trim$(record) <> "procesados" then
string.scan(record,"%s",NameFile)
client2server("C:\trash\get\"&NameFile, "/export/home/get/test/cpx/"&NameFile, false, false)
endif
endwhile
|cierro archivos
seq.close(fp1)
endif
|Lectura de archivos en directorio del servidor
counter = 0
fpath = "/export/home/get/test/cpx"
fd = dir.open(fpath)
if fd < 0 then
mess("zmadms0046", 1, fpath)
|* Directory Handling Errors: %1$s
end()
endif
fname = dir.entry(fd, TFILE, rt, size, mode)
while (not isspace(fname))
if trim$(fname) <> "get.txt" and trim$(fname) <> "filenames.txt" then
counter = counter + 1
fp = seq.open(fpath&"/"&fname, "r")
if fp < 0 then
mess("zmadms0036", 1, fname)
|* File Opening Error: %1$s
e = seq.close(fp)
continue
else
formatea.archivo()
procesa.archivo()
mueve.archivo()
|* file found - do.something......
e = seq.close(fp)
endif
endif
fname = dir.entry(fd, TFILE, rt, size, mode)
endwhile
e = dir.close(fd)
if counter <= 0 then
mess("zmadms0045", 1, fpath)
|* No files in directory: %1$s
exit(1)
else
message("%d files in directory %s", counter, fpath)
endif
}
function void formatea.archivo()
{
extern string InitFile(256), record2(2048), subCadena_get(22), subCadena(22)
long fp2, sizeString, flagWrite, index
subCadena = "<comprobante><![CDATA["
InitFile = fpath&"/"&fname
fp2 = seq.open(InitFile,"r")
| Valido si hubo erro
if fp2 >= 1 then
flagWrite = 0
| comienzo a leer los archivos
while seq.gets(record2,2048,fp2) = 0
| Separo en registros la cadena del string
sizeString = len(record2)
index = rpos(record2, "<comprobante><![CDATA[")
if index > 0 then
subCadena_get = (record2(index;22))
endif
if subCadena_get = subCadena and flagWrite = 0 then
record2 = record2(index+22;sizeString)
flagWrite = 1
endif
if flagWrite = 1 then
make.new.file()
endif
endwhile
| cierro archivos
seq.close(fp2)
endif
}
function make.new.file()
{
long out.fp
long r_log
|Abro o creo el archivo y lo asigno a un puntero
out.fp = seq.open(strip$(InitFile&"_new"),"a+")
|Valido que el archivo se pudo abrir
if out.fp < 1 then
message("El archivo : " & InitFile&"_new" & " no puede ser generado")
endif
|Coloco la información en el log, en función del puntero
r_log = seq.puts(strip$(record2),out.fp)
seq.close(out.fp)
}
function procesa.archivo()
{
|parsear el xml y tomar los campos necesarios
|grabar en tabla temporal la información existente en los archivos *_new
|validar contra maestros los datos ->registrar fases, estatus y mensajes de error de ser el caso
|Procesar por AFS ->registrar fases, estatus y mensajes de error de ser el caso
|relectura de la tabla para arrojar expceciones a un archivo
}
function mueve.archivo()
{
app_start("cmd /c move C:\trash\get\"&fname&"C:\trash\get\procesados\"&fname , strip$(local.dir), "", "", "")
}
I hope that this can help you!!