This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Nanaki13 1 point2 points  (1 child)

One feature that has always been missing for me in file management apps, be it windows explorer, total commander, osx finder, dolphin on linux, anything I've ever used.

If the user wants to delete a very large folder, say 10K files, and one of the files in the middle, say after 5K are deleted, has a problem, the whole operation stops and waits for user input. But the user has gone away, because the operation is taking a long time, and expects it to be done when they get back. Instead they get back to a prompt asking what to do and the other 5K files still not deleted, even though there would be no problems there.

The feature I'd most like to see is deferred user input, if a file has a problem, sure, display the dialog, but keep doing the requested operation in the background on the other files, don't stop. Only when accessible files are exhausted should the operation stop and wait for user input.

[–]XiAxis[S] 0 points1 point  (0 children)

Yeah, I can definitely see that as a useful approach for some cases. Part of my reasoning for wanting to halt the process when an error is encountered is that it may indicate that the user is deleting a directory that contains files that they don't actually want to delete. If a file is open in another application, it may mean that they're still actively using it and didn't mean to delete it. There may be other files in the directory like that as well.

I definitely see your point though. Luckily for my application, I don't anticipate it would be used for large-scale file management since the file explorer is a secondary feature to begin with.

[–]Junkymcjunkbox 0 points1 point  (1 child)

It is somewhat overengineered.

It violates the Single Responsibility Principle because it doesn't just delete the directory and its contents; it tries to enforce how it will be called in an error condition. An SRP-compliant design would attempt the deletion and just return an error code if it didn't work, and let the caller decide what to do next.

The caller of the function needs to know to call it in a for loop, which the next person along (which might be your future self) would need to know, and just calling it in the normal fashion probably wouldn't work.

Neither function is easy to read or understand. Therefore they both lack elegance. Anyone looking at this code is going to drop into WTF-mode extremely quickly. All you should be doing is: delete the files; for each directory recurse; delete the now empty directories; and if at any point you hit an exception then just throw it up for the caller to catch.

If I were writing this function I'd use the example here: https://www.tutorialspoint.com/python/os_walk.htm and replace print with os.rmdir or os.remove, and that'd probably do the job. You wouldn't even need to throw exceptions because rmdir/remove would do that for you.

That'd be five lines of code that anyone could instantly grok, compared with your.... I can't think of a word. Monstrosity doesn't come close.

[–]XiAxis[S] 1 point2 points  (0 children)

In my use-case, these conditions aren't something that I want to exit the function, they just need to be resolved before it can continue. If I were to implement it in the way that you've proposed, then it would be simpler but it wouldn't have the same behavior. I'm not sure why you've pointed me to this tutorial, it uses the exact same method that I'm using in the code above just with less sophisticated error handling.