What would be a portable way to determine if a Python process can move/delete a file without having to move/delete the file in question?
Use case: I'd like to inform the user of a script whether or not move/delete operations will succeed/fail prior to starting processing.
If there is a solution that only works in Linux, I'd be OK with that for the moment.
Thanks.
update: I understand that os.access can be used but is limited to real uid/gid.
Browse File Explorer, and once you find the file to be deleted, right click, and click on "Delete", or press the Delete key, or drag the file to the Recycle Bin.
Does Windows 10 Have a File Shredder? Windows do not come with a built-in file shredder. It cannot shred and delete a file in its entirety. It, however, has a built-in Command Prompt command to erase an entire disk or drive.
Would opening the file for append work?
try:
open(filename,'a').close()
...and catch any exception indicating that failed?
Use with caution, I'm really not sure that wouldn't do anything nasty by mistake. For example at least temporarily you'll have locked the file, and I don't know what that would do to a binary file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With