Can Igor delete directory (folder) on user disk?
ilavsky
I need to create temporary directory (folder) on user hard drive and I would prefer to delete it after use for users. I can probably run some ugly ExecuteScriptText (platform specific...) but it would be easier to let Igor delete the directory/folder for me, since it was created by NewPath command anyway.
I think I recall asking about it years ago with answer "no"... But cannot find my notes and my be I am missing something, searching manual has not helped. Can we some how do it? Can we, for example, MoveFolder somehow to trash?
You're looking for DeleteFolder. Unless the user has edited a 'Misc' setting, DeleteFolder enforces a dialog to ask for user confirmation. I use this in my recently updated package installer.
Unfortunately, there's no way that I've found to move files to trash. That would be useful.
March 31, 2020 at 12:53 am - Permalink
Tony is right that DeleteFolder is probably what you're looking for, though there's no way to move to the trash rather than deleting outright.
I have attached an "ugly ExecuteScriptText" solution (which is, as you described, quite ugly). We use this in our internal testing framework that runs unattended with default permissions so can't use DeleteFolder.
On Macintosh with macOS 10.14 or later, the first time this runs the OS will ask if Igor has permission to run Applescript. The OS remembers your choice there, so future runs shouldn't ask the question. Users might be a bit hesitant to answer yes to that prompt.
I found a javascript based Windows script host script that claims to do this (https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/deleteJS.bat). I know you love that approach :) <ducks>
On Macintosh you might be able to modify the AppleScript command above to move the folder to the trash instead of deleting it outright.
An alternative that might work for you would be to create the folder in the user's temporary directory. In that case the OS will take care of deleting it for you, though that may not be what you want.
March 31, 2020 at 04:50 am - Permalink
I would consider Adam's alternative, the OS default temporary location can be fetched via
C:Users:thomas:AppData:Local:Temp:
and that is writeable by the current user.
MoveFolder from your current location without overwriting an existing folder might do the trick as well.
March 31, 2020 at 05:24 am - Permalink