DzApp.getTempFilename() doesn't seem to clean-up after itself.

Hello All,

According to the documentation, DzApp.getTempFilename() should clear up any files in the temp_dirs it creates when Daz shuts down. Unfortunately, this doesn't seem to be the case. I've worked around this by keeping track of the temp dirs that are created in my script and then before my script ends, I clear them up with the following code:

 

for(var i = 0; i < app_temp_dirs.length; i++) {
  
  // remove files in dirs
  var dir_to_nuke = DzDir(app_temp_dirs[i]);
  var files = dir_to_nuke.getFilesFromDir(["*.*"], true);
  for(var f = 0; f < files.length; f++) {
    dir_to_nuke.remove(files[f])
  }
  
  // remove dirs
  dir_to_nuke.rmpath(app_temp_dirs[i]);
}

 

The files get removed perfectly. However, any call to DzDir.rmpath(path_to_remove) that I try fails. Which means I'm left with a ton of empty dir structures.

I have tried relative paths, absolute paths, I've used DzDir.cdUp() to maybe get out of the way. etc. etc. etc. But I can't get it to work.

Would some kind soul put me out of my misery and tell me how it's done?

Comments

  • andya_b341b7c5f5andya_b341b7c5f5 Posts: 694
    edited August 2020

    The docs say that files in the 'current temporary working folder' will be deleted when shutdown() is called.

    If I create some files in this 'current temporary working folder' they are indeed deleted when DS is shut down.  Subfolders within this folder, and files within those subfolders, do not appear to be affected.

    ETA: Creation and removal of a folder (must be empty).

    // DAZ Studio version 4.12.0.86 filetype DAZ Scriptvar tp = App.getTempPath();print('tp: ', tp);var dir = DzDir(tp + '/MyTempDir');print(dir.absolutePath());dir.mkpath(dir.absolutePath());var tfnArray, tfn;for (i = 0; i &lt; 6; i++) {	tfnArray = App.getTempFilename().split("/");	tfn = tfnArray[tfnArray.length -1];;	var tf = DzFile( tp + '/' + tfn + '.txt');	//print(tf.absolutePath());	if (tf.open(DzFile.ReadWrite)) {		tf.close();	}	else { print('Not open') }	print(tf.fileName())}//Better way to test folder is empty?var entries = dir.entryList();if (entries.length == 2 &amp;&amp; entries[0] == '.' &amp;&amp; entries[1] == '..') {	print('Empty!');	dir.rmpath(dir.absolutePath());} else { print('Not empty, delete some stuff!'); }if (!dir.exists()) {	print('Gone!');} else { print('Not gone, huh?') }

     

    Post edited by andya_b341b7c5f5 on
  • Thnx for your efforts. Will give it all a go over the weekend :)

Sign In or Register to comment.