%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
N 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'="" {
N 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
.N 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)
.W FILE_$C(13)_$C(10)
.W 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.
... .SET SC=STREAM.LinkToFile(FILE) // A ... ... .do ##class(%File).Delete(FILE, .RETURN) // B
As long you hold your hand on a file (line A), you can't delete the file (line B). You have to do something like
set SC = "" // or kill SC
Bye the way, non of Cache/IRIS has an $ZU command but all versions have a bunch of $ZU() functions. So what do you want to do with them?
I read some random post in the community that said you could evaluate the low level return with the $ZU() command. But maybe that was something different
Neither of those command worked, that was what I thoguht at first too. But killing the STREAM did the trick, so you pointed me in the right direction. Thanks.
Check acces rights to the files.
Especially for the Windows USER your Caché installation is runing on.
Windows error codes are here.
ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.
oh nice, thanks!