· Jun 6

RemoveDirectoryTree not working

Hi Guys,

I'm using the below code to download, extract files in a file directory then save data into a global, and remove the file directory as not needed anymore, but the issue is that the class(%File).RemoveDirectoryTree is not deleting, also tried class(%File).RemoveDirectory and same thing.

I'm suspecting that maybe because the process is still considering the file or the directory is opened or still in use !? I also tried to run the class(%File).RemoveDirectoryTree("D:\SpaceSense2014\LIVE-SPACESENSE\NodeJS\FFTData_20019082")  from the terminal and still nothing ?

The  two class(%File).Delete() are working fine because they are deleting files oustide that directory but not the RemoveDirectoryTree.


Set FileUnZip = "D:\SpaceSense2014\LIVE-SPACESENSE\NodeJS\FFTData_"_ID
Set FileZip = FileUnZip_".csv.gz"
Set FileAfUnZip = FileUnZip_"\FFTData_"_ID_".csv"
Set JsPath = ##class(SX3.Task.AWSService).FFTFileDownload(ID,Sensor,MeasureDT)
Set stream=##class(%FileCharacterStream).%New()
Set stream.Filename=FileAfUnZip
While 'stream.AtEnd {
Set ReadFFTData=stream.ReadLine()
 X = +$P(ReadFFTData,",",8)
Y = +$P(ReadFFTData,",",9)
Z = +$P(ReadFFTData,",",10)
Label = +$P(ReadFFTData,",",6)




Product version: Ensemble 2018.1
Discussion (5)1
Log in or sign up to continue

RemoveDirectoryTree(some_dir) works, if it returns FALSE to you so
- either your Ensemble instance has no rights to delete files and directories
- or you feed RemoveDirrectoryTree() with a filename or with a  nonexistent directory

Try the following:

write FileUnZip,! // this should be an existing DIRECTORY
write ##class(%File).Attribute(FileUnZip),! // this should be 16 (on Windows)
write ##class(%File).RemoveDirectoryTree(FileUnZip),! // 1=removed, 0=not-removed

Thanks Julius I found the problem, the reason why the directory couldn't be removed because the command before was holding it because it's deleting a file inside the directory the last command is trying to do.

so  ##class(%File).Delete(FileZip) is deleting a file inside the directory "FileUnZip"  (##class(%File).RemoveDirectoryTree(FileUnZip))

I've removed the first call and now the second is execute Ok