Question
· May 25, 2022

%File Delete not Working

Hey there,

I'm writing an import Routine to read files into a global. The code is working fine except for the 'Delete' command. The files are being imported, copied but not deleted. Maybe someone has an Idea what ist happening.

I get the low level return value of -32 but i couldn't find anywhere to show me what that actually means. And my Caché version doesn't support the $ZU command.

Here's the Code

WWWFILEIMPORT
 PATH,FILE,ARCHIVPATH,FAILPATH
 SET PATH="C:\inetpub\ftproot\File_Import\"
 SET ARCHIVPATH="C:\inetpub\ftproot\File_Import\Imported\"
 SET FAILPATH="C:\inetpub\ftproot\File_Import\Failed\"
 set FILE=$ZSEARCH(PATH_"*")
 WHILE FILE'="" {
 FILESTART,FILENAME
 SET FILESTART=$LENGTH(FILE)+2-$FIND($REVERSE(FILE),"\")
 SET FILENAME=$E(FILE,FILESTART+1,99999)
   
 IF $G(FILENAME)'="" IF $G(FILENAME)'="." IF $G(FILENAME)'=".." IF $F(FILENAME,".") DO
   .STREAM,SC,LINE,DATA,LIMIT
   .SET LIMIT=0
   .SET STREAM=##class(%Stream.FileCharacter).%New()
   .SET SC=STREAM.LinkToFile(FILE)
   .DO STREAM.Rewind()
   .SET DATA=""
   .WHILE 'STREAM.AtEnd {
   .SET LINE=STREAM.ReadLine()
   .IF ($L(DATA)+$L(LINE))>3600000 SET LIMIT=-1
   .IF LIMIT=-1 Q
       .SET DATA=DATA_LINE_$C(13)_$C(10)
    .}
    .
    .IF LIMIT=0 IF $G(DATA)'="" SET ^WWWFILE(0,FILENAME,1)=$G(DATA)
    .
    .
    .
    .IF LIMIT'=-1 DO ##class(%File).CopyFile(FILE,ARCHIVPATH)
    .IF LIMIT=-1 DO ##class(%File).CopyFile(FILE,FAILPATH)
    .
    .do ##class(%File).Delete(FILE, .RETURN)
    .FILE_$C(13)_$C(10)
    .RETURN
    .
    .Q
 
 SET FILE=$ZSEARCH("")
 }
 Q

 Output for a single file is: 

C:\inetpub\ftproot\File_Import\app-debug.apk
-32

Thank you for any advice.

Product version: Caché 2017.1
$ZV: Cache for Windows (x86-64) 2017.2 (Build 744U) Fri Sep 29 2017 10:58:27 EDT
Discussion (7)1
Log in or sign up to continue