Ir al contenido principal

Gestione file


FUENTE ORIGINAL = https://kb.sagedev.it/index.php?title=Gestione_file 

https://kb.sagedev.it/

Jump to navigationJump to search


Dimensione dei file[edit]

Per sapere la dimensione di un file:

filinfo(YFILEI,7)

è anche un modo per sapere se il file esiste:

If filinfo(YFILEI,7)<0
  Infbox "File non trovato"
  End
Endif

Scrittura/Lettura[edit]

Codice di esempio per la lettura/scrittura di file:

   
Local Char YFILEI(250),YFILEO(250)
Local Clbfile YETI(4)

YFILEI = filpath("TMP\ETICHETTE",'Eti_Standard',"eti")

If filinfo(YFILEI,7)<0
    Infbox "File di input non trovato"
    End
Endif

YFILEO = filpath("TMP\ETICHETTE",'Etichetta', "txt")

adxirs = ''

# apro il file YFILEI in lettura
Openi YFILEI,0 Using [YIN]  
# leggo il file e metto in YETI
Rdseq YETI Using [YIN]
# chiudo il file
Openi Using [YIN]

...

# apro il file in scrittura
Openo YFILEO,0 Using [YOUT]
#scrivo sul file
Wrseq YETI Using [YOUT]
# chiudo il file
Openo Using [YOUT]


Per leggere i dati caricandoli su un clob:

Local Char YFILEI(250), YFILEO(250)
Local Clbfile YETI(4)

YFILEI = filpath("TMP\ETICHETTE",'Eti_Standard',"eti")
YFILEO = filpath("TMP\ETICHETTE",'Eti_OUTPUT',"txt")

Openi YFILEI,0 Using [YIN]          # apro il file YFILEI in lettura
  Iomode  adxirs ''   Using [YIN]   #dopo l'apertura del file, contiene il separatore di record usato da Rdseq e Wrseq. Per leggere tutto in un'unica volta impostare come vuota
  Iomode  adxifs ''   Using [YIN]   #dopo l'apertura del file, contiene il separatore di campo
  Iomode  adxium 50   Using [YIN]   #dopo l'apertura del file, codifica ASCII, necessaria per clob

Rdseq YETI Using [YIN]              # leggo il file e metto in YETI
Openi YFILEI Using [YIN]            # chiudo il file

Openo YFILEO,0 Using [YOUT]
Wrseq YETI Using [YOUT]
Openo YFILEO Using [YOUT]

Cancellare[edit]

Call SYSTEME(adxmac(1),'ae_rm '+PATHFILE,"",STAT) From ORDSYS

(per maggiori info vedi SYSTEME From ORDSYS)

Call EFFACE(PATHFILE,"",STAT) From ORDSYS

in V7: RETURN_STATUS=delFile(Path)

Creare cartella[edit]

Call SYSTEME(adxmac(0),'ae_mkdir '+PATHFILE,"",STAT) From ORDSYS Call SYSTEME(adxmac(0),'ae_mkdir'-'"'+PATHFILE+'"',"",STAT) From ORDSYS

Spostare[edit]

Questo comando è stato usato da server X3 a percorso di rete.

Call MOVE (FILE_SRC, CARTELLA_DEST, YSTAT) From ORDSYS

Copiare file esterni[edit]

Per copiare un file da client (scelto interattivamente dal'utente) in un file su server X3

    Local Integer STAT
    Local Char FICCLI(250)
    Local Char FICSRV(250)
    FICSRV= "c:\SAGE\SAGEX3V6\X3V6\Folders\"+nomap(0)+"\TMP\nomefile.txt"
    FICCLI = GDIREXP+"\*.pdf"  #GDIREXP contiene al cartella di default per utente da dove selezionare i file
    Call COPSRV(FICCLI,FICSRV,STAT) From ORDSYS

COPCLI serve invece per la direzione opposta, da server X3 a client

Call COPCLI(FICSRV,FICCLI,STAT) From ORDSYS

Per copiare un file da una cartella ad un'altra entrambe in percorsi di rete utilizzare la chiamata COPIE (attenzione al maiuscolo/minuscolo!) Se il file di destinazione esiste già viene sovrascritto.

Local Char SRC(250)
Local Char DES(250)
Local Integer STAT
DES="\\sagedev\sage\Dossier\SAGEDEV\TMP\DP\test.pdf"
SRC="\\srvdev\TMP\xxx\esempio.pdf"
Call COPIE(SRC,DES,STAT) From ORDSYS

Verifica presenza file e cartelle[edit]

Call EXISTE(PATH,EXIST) From ORDSYS restituisce:

  • 0 se non esiste
  • 1 se è un file
  • 2 se è una cartella
    Local Integer EXIST
    Call EXISTE(PATH,EXIST) From ORDSYS
    If EXIST <> 1
        Errbox "file non presente"
    Endif


Il modo diretto è il seguente (maggiori info nell'help in linea di filinfo):

Local Integer RETDIR 
RETDIR = filinfo(PATH,0)
   
If RETDIR<0 or int(mod(RETDIR/4096, 16)) <> 4
   Errbox "directory non presente"
Endif


Più semplicemente se è un file si può fare così:

If filinfo(YFILEI,7)<0
    Infbox "File di input non trovato"
Endif

Per verificare la presenza di un file in un client usare

call EXICLI(FICCLI,STAT) from ORDSYS


Recuperare la lista dei file presenti in una cartella (attenzione a maiuscolo/minuscolo: *.txt è diverso da *.TXT)

Local Char PATH(250)
Local Char LISTAFILE(100)(1..1000)
Local Integer NUMFILE
PATH ="\\SAGEDEV\car1\A*"
Call SYSTEME2(adxmac(0),"lsadx"-PATH,"",NUMFILE,LISTAFILE) From ORDSYS     
NUMFILE = min(NUMFILE,dim(LISTAFILE))     #nel caso in file siano più di quelli contenuti nell'array

Elenco file di una cartella[edit]

Il comando da utilizzare è

Call SYSTEME2 (adxmac(0),”lsadx”-DIR,””,LENGTH,FILELIST) From ORDSYS

Questa chiamata recupera il risultato del comando eseguito. Se non serve recuperare il comando basta usare SYSTEME (senza l'ultimo parametro di output).

Parametri:

  • DIR: Nome directory (non deve contenere spazi)
  • LENGTH: numero di file presente nella directory.
  • FILELIST: Lista dei nomi dei file presenti nella directory (non devono contenere spazi). Deve essere una matrice di Char
Local Char DIR(GDIMFIC), FILELIST(GDIMFIC)(1..100)
Local Integer LENG
DIR="C:\test"
Call SYSTEME2 (adxmac(0),"lsadx"-DIR,"",LENG,FILELIST) From ORDSYS
For I=3 To LENG               #I=3 per saltare le due cartelle . e ..
     InfBox FILELIST(I)
Next

Oppure, con caratteri jolly, per recuperare tutti i file ODA*:

Local Integer NUMFILE
Local Char LISTAFILE(100)(1..1000)
Local Char PATH(100), FICBAS(100)
PATH = ...
FICBAS='"' + "ODA*" + '"'
Call SYSTEME2(adxmac(0),"lsadx"-PATH-FICBAS,"",NUMFILE,LISTAFILE) From ORDSYS     

For I=1 To LENG               
     InfBox FILELIST(I)
Next

Il comando deve essere scritto così: lsadx \\srvint1\IntranetPDF\hlp "*.pdf"

In realtà è possibile lanciare qualsiasi comando dos, e recuperarne lo standard output:

Local Char DIR(GDIMFIC), FILELIST(GDIMFIC)(1..100)
Local Integer LENG
DIR="C:\temp" 
Call SYSTEME2 (adxmac(0),"dir /b "-DIR,"",LENG,FILELIST) From ORDSYS
For I=3 To LENG               #I=3 per saltare le due cartelle . e ..
     InfBox FILELIST(I)
Next


Altro modo con forfiles

    Char CMD(100)
    CMD='forfiles /p'-MIO_PATH-'/m *.* /c "CMD /C ECHO @File"'
    System FILES = adxmac(1)+'@cmd.exe /C '+CMD        #System permette di eseguire un comando di sistema
                                                       #stat1 conterrà il numero di righe restituite dall'istruzione System

    Local Char    FILES(100)(stat1)
    For YIND = 1 To stat1-1  #partire da 1 per evitare la prima riga sempre vuota
         Infbox FILES(YIND)
    Next

Estensione[edit]

Non ho trovato un modo nativo per recuperare l'estensione di un file; riporto qui un metofo banale :

Subprog GET_EXT(NOMEFILE, ESTENSIONE)
Value Char NOMEFILE()
Variable Char ESTENSIONE()
    Local Integer I,PREC
    I=0
    Repeat
        PREC=I
        I = instr(I+1, NOMEFILE, ".")
    Until I = 0
    ESTENSIONE=""

    If PREC
        ESTENSIONE= tolower(right$(NOMEFILE,PREC+1))
    Endif
End

Altri comandi[edit]

filpath(..)

filinfo(..)

dir$

Esempio: costruzione di un percorso qualsiasi

[L]PATH = filpath([L]DIR, [L]NOMEFILE, [L]ESTENSIONE, [L]DOSSIER, [L]VOLUME, [L]SERVER)

filpath("DIR","NOMEFILE","ESTENSIONE","SAGEDEV")             # =>  "C:\SAGE\SAGEX3V6\X3V6\Folders\SAGEDEV\DIR\NOMEFILE.ESTENSIONE"
filpath("DIR","NOMEFILE","ESTENSIONE","SAGEDEV","A")         # =>  "C:\SAGE\SAGEX3V6\X3V6\Folders\SAGEDEV\DIR\NOMEFILE.ESTENSIONE"
filpath("DIR","NOMEFILE","ESTENSIONE","SAGEDEV","A","srvx3") # =>  "srvx3@C:\SAGE\SAGEX3V6\X3V6\Folders\SAGEDEV\DIR\NOMEFILE.ESTENSIONE"

filpath(CARTELLA,nomefile,estensione) costruisce il path assoluto di un file:

se CARTELLA inizia per "\\" mantiene la cartella così come passata nel parametro
se CARTELLA inizia per "\" da un percordo del tipo "C:\CARTELLA"
se CARTELLA non inizia con la barra, da un percorso del tipo "C:\SAGE\SAGEX3\Folders\DOSSIER\CARTELLA\nomefile.estensione"


Tra le altre cose permettono un test dell'esistenza di una tabella; esempio

# Test dell'esistenza della tabella 'CLIENT' nell'applicazione corrente    
If filinfo(filpath('FIL','CLIENT','fde',-1),1) <0 : Goto INEX : Endif

Caricamento[edit]

Carico di un file da client verso file su server

Local Integer STAT
Local Char FICCLI(250)
Local Char FICSRV(250)
FICSRV= "c:\SAGE\SAGEX3V6\X3V6\Folders\"+nomap(0)+"\TMP\YDOC_"+format$("D:YYYYMMDD[_]hhmmss",date$)+"_"+GUSER+".pdf"
FICCLI = GDIREXP+"\*.pdf" 
       
Call COPSRV(FICCLI,FICSRV,STAT) From ORDSYS

Per modificare la dimensine massima dle file caricabile, modificare il file di configurazione nodelocal.js di Syracuse:

upload: {
        fileMaxSize:

{ default: 20, //default max size in MB

patchUpdate: 500 //max size of patchFile in MB }
    },

adxirs e adxifs[edit]

adxirs è una variabile stringa di massimo 2 caratteri che contiene il record separatore usato dalle istruzioni Rdseq e Wrseq per la lettura/scrittura sequenziale dei file. Ogni elemento in una lista data come argomento in Rdseq o Wrseq è separata da questo valore. Per leggere tutto il file in un'unica volta bisogna impostare come vuota questa variabile.

Alla fine del file invece, sia in scrittura che in lettura viene considerato il separatore di linea inidicato da adxifs. Va notato che è una variabile globale valida per tutti i file aperti.

Per avere un controllo per ogni singolo file aperto bisogna usare l'istruzione Iomode (consigliato).

Entradas populares de este blog

Valores de fstat

Fstat fstat  is a numeric status that is returned upon execution of a database operation, a sequential file operation, or a lock instruction. Syntax fstat Examples # MYTABLE is a table with a key called KEY1, that has a unique component called KEYVAL # Create a record in the table MYTABLE with they key value 1 if it doesn't exist Local File MYTABLE [MYT] Read [MYT]KEY1=1 If fstat [MYT]KEYVAL=1 : Write [MYT] If fstat MSG="The key was created in the mean time" Else MSG="Key created" Endif Else MSG="Key already exists" Endif Details fstat  is always set to '0' if the operation is successfully completed, and has a non-null value if there is an error: In a sequential read ( Getseq  and  Rdseq ),  fstat  is set to '1' at the end of the file. On  Lock ,  fstat  is set to '1' if the lock could not be performed. For a database operation ( Read ,  Look ,  Readlock ,  For ,  Write ,  Delete ,  R

3 ways to send a mail from code in Sage X3, with more attachments too

Origen Fuente:  https://en.sagedev.it/sagex3/send-mail-from-code-with-attachments-sage-x3/ Autor:  https://en.sagedev.it/category/sagex3/ In this post I’ll show you how to send a mail from adonix code in Sage X3. The points we will face are: 1) Meladx/Send introduction 2) Sending  through  meladx (the best way for me: at the end with just a single code line you send a mail!) 3) Sending  through  Workflow 4) Sending  through  ENVOI_MAIL(…) From AWRKMEL Sending mail from code in Sage X3: Send vs meladx Sage X3 has two native ways for sending mails. The first way is  meladx  executable file, that you can find in  runtime\bin  directory. The seconde one is Send instruction, that was used to send mail through an application of the client station (for more information on “Send GSERMES”  go here ). The Meladx executable Meladx send messages through SMTP/POP3 protocols by means of the mail  server  specified in the command. When sending is launched by a work

How to upload a file from the client?

You may have a need to upload a file to the server, and in the past you may have used COPSRV routine from ORDSYS. On V6 the limit that this routine had was that, you did not know the file name of the file that is getting transferred to the server, and you had to define the file name for the destination.  But things have changed on newer version. Before we get to the example review online help title "How to manage files in the storage area"  As you noted in the online help, in the new version COPSRV will copy the file to server TMP directory. So in below example I am going to use another routine MOVE from ORDSYS to move the file to my desired location. In this example, I am adding a button to Sales order, for transferring the file. Open  Development, Script dictionary, Windows. Select  OSOH  window. Add a new button.  Save  and  Validate. Open  Setup, Sales, Entry transactions, Orders. Validate  the entry transaction. Now open  Development, Scr