I'm working on a function that flattens a directory by moving the contents of all subfolders into the current folder, operating recursively as needed. The last detail is to delete empty folders after taking all the stuff out but the DeleteFolder function lacks a flag to prevent user-prompts. I don't want to change Misc->"Operations that overwrite/delete..." because this function is intended to share and other users would not appreciate having to change this option. (It is a good one!)
Hopefully there is a way to programmatically (and temporarily) change that setting. Or there is some secret flag for DeleteFolder. Or someone knows how to use MoveFolder to relocate empty folders to the Recycle Bin/Trash. Or relocate them to a temp dir so the OS can delete them? None of these ideas seem plausible... Does anyone have suggestions?
There is no programmatic way to temporarily set the Misc Settings setting about deleting folders on disk. There is also no programmatic way to know what that setting is so you could tell the user to change it and rerun the procedure.
You may be able to use ExecuteScriptText to move the folder to the trash. That would have to be done differently for Macintosh and Windows.
You could move the folder to the Temporary directory. Use SpecialDirPath to get the users Temporary directory. Looking at my temporary directory on Mac OS X, it appears that the OS does empty it when you shut down or restart. On Windows XP, it appears that the OS does not empty it. That may not be a big deal.
You could create a folder and move all of the empty folders into it for neatness, and tell the user to manually delete it or move it into the temporary folder.
October 12, 2011 at 08:08 pm - Permalink
I would suggest, rather than doing such directory-level management from in Igor, to ship out a command to let the OS handle it. IOW, create a shell script / AppleScript on Mac or whatever is equivalent on Windows. Have the script take the directory name and go with it. Have it return OK / NOT OK flags. Then, run the script from Igor (ExecuteScript ...) either as a background task or a pre-emptive task that waits for proper return before continuing.
I would also suggest having the shell script first create a copy of the directory (perhaps even an archive) in case a mistake is made and a restore option is needed.
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
October 13, 2011 at 07:59 am - Permalink
October 13, 2011 at 08:35 am - Permalink
hrodstein, you read my mind about checking the setting and prompting the user - that option dawned on me last night. And good tip on the Mac temporary folder being emptied upon restart. That may become part of the solution.
Since I think users would prefer to have their files recoverable, I'm going to try to move the folders to the recycle bin/trash rather than delete them outright. On Windows, finding the user's recycle bin path is not trivial so rather than MoveFolder, I'm going to try ExecuteScriptText with a third-party program called recycle.exe, part of CmdUtils from MaDdoG. On Mac, I'll code it to move files into the tempdir but I wonder if the AppleScript from aclight could be made to recycle instead of delete. (I don't have a Mac... maybe it already does)
October 13, 2011 at 11:14 am - Permalink
See http://macscripter.net/viewtopic.php?id=24394
October 13, 2011 at 02:04 pm - Permalink
I found the same page. Thanks aclight! I should just refresh the forums more often. :)
October 13, 2011 at 02:22 pm - Permalink
It behaved well on Windows. I expect it should work on Macintosh too.
October 13, 2011 at 05:52 pm - Permalink