简体   繁体   中英

Python os.rename if file system is full

I'm asking this beacause there's no way to try it myself (if there's one share it please (:).

I'm doing some file handling with Python os library, specifically file moving/renaming with os.rename().

Python docs explains some of the exceptions this function might raise here , but do not say anything about a full file system case. My guess is it raises an IOError, is this right?

Cheers.

In practice this should rarely come up, but if you want to test I'd recommend creating a small file system (I don't know what OS you are on, but this could be on a virtual partition, a RAM disk, a flash drive, etc.) and loading it up with garbage files to see what happens. Something like this maybe:

aBigNumber = 100000000000000000000000000000000
counter = 0
while (True):
    counter += 1
    anotherFile = open(`counter` + ".txt", "wb")
    anotherFile.write("0" * aBigNumber)
    anotherFile.close()

When you get an exception, you should be able to verify that the disk is full and then you'll know what kind of error to expect.

You can test it by filling up a small partition and then try the file operations on the filled filesystem. On *nix systems you can mount a tmpfs; for windows maybe use a usb stick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM