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)
D ##class(SX3.Task.AWSService).ExecuteCmd(JsPath)
D ##class(SX3.Task.AWSService).UnZipExtract(FileZip,FileUnZip)
Set stream=##class(%FileCharacterStream).%New()
Set stream.Filename=FileAfUnZip
While 'stream.AtEnd {
Set ReadFFTData=stream.ReadLine()
S X = +$P(ReadFFTData,",",8)
S Y = +$P(ReadFFTData,",",9)
S Z = +$P(ReadFFTData,",",10)
S Label = +$P(ReadFFTData,",",6)
S ^DumpTempFFT(Equipment,Sensor,ID,$I(j))=X_"^"_Y_"^"_Z_"^"_Label
S Total=Total+1
}
D ##class(%File).Delete(JsPath)
D ##class(%File).Delete(FileZip)
D ##class(%File).RemoveDirectoryTree(FileUnZip)
Thanks
Comments
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 DIRECTORYwrite##class(%File).Attribute(FileUnZip),! // this should be 16 (on Windows)write##class(%File).RemoveDirectoryTree(FileUnZip),! // 1=removed, 0=not-removedThanks 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 D ##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
Thanks
BTW is there a way to delete files where their name starts with.. eg. all file start with Myfile*?
Thanks
##class(%File).Delete("c:\tmp\deleteMe*")
Thanks Alex