Hot answers tagged

4

Since the split files do not need to be readable text files, I would read & write in chunks of bytes, not in lines. This should be faster than reading and writing line by line. We can go with a chunk size of 4,096 bytes because 4,096 or 8,192 is a typical block size on most file systems. Although, I should note that when I tested your script on my system ...


3

Since you are already requiring the filename to start with the correct drive name, your target will already look like a normal valid path. So you could at least check if what the user entered is actually the correct path, short-circuiting the whole search: def search(drive, target): if os.path.isfile(target): return os.path.abspath(target) ......


2

What would you change in this code? I'd simplify the split function. Not counting lines and files myself and opening/closing the output files at different places without a with statement. Just always try to read another line and if that succeeds, put it and the next up to split_size - 1 lines into another output file. def split(self): print(&...


1

Your description appears to suggest you're reimplementing wipe; I recommend you read its sources to see what an effective implementation looks like. I'll note that the concept could well be flawed if you're writing to a log-structured filesystem or to wear-levelling media - both of those need specific actions to erase data, because overwriting will simply ...


Only top voted, non community-wiki answers of a minimum length are eligible