New answers tagged

4 votes

Remove all text files with non-US-ASCII text encoding from current folder on Linux

Use nftw() to recursively iterate over the directory A lot of code you wrote is spent to recursively iterate over all the directory entries. That can all be avoided ...
G. Sliepen's user avatar
  • 54.2k
6 votes

Remove all text files with non-US-ASCII text encoding from current folder on Linux

char current = fgetc (text_file_pointer); discards the difference between an error (int -1) ...
Peter Cordes's user avatar
  • 3,266
8 votes

Remove all text files with non-US-ASCII text encoding from current folder on Linux

#define SUCCESS 0 #define FAIL -1 Better to include <stdbool.h> and use its defined ...
Toby Speight's user avatar
  • 74.5k
8 votes
Accepted

Remove all text files with non-US-ASCII text encoding from current folder on Linux

I'd have a function to check if a file is ASCII compatible (a positive check just to be sure that we don't get double negatives). Then if that's not the case I'd remove the file. Then I would have a ...
Maarten Bodewes's user avatar
3 votes

Java code to delete all empty folders within a directory

You're using an actual logger - that's good. However, for the errors that appear in cleanupDirectory, it's probably a better idea to throw an exception. The caller ...
Reinderien's user avatar
  • 60.8k
3 votes

Java code to delete all empty folders within a directory

You're not taking into account loops created by symbolic links. This may not be a problem to your use case but in a generic case it will lead to a stack overflow error. A quick but a bit dirty fix ...
TorbenPutkonen's user avatar
2 votes
Accepted

Looking for help simplifying a general purpose compression function

Replace your os module import with pathlib and use more Path. Add PEP484 types to your ...
Reinderien's user avatar
  • 60.8k

Top 50 recent answers are included