I've got code that's exporting a file, but the file might be so big that it will take up too much space on the cluster I'm using and crash other users' processes. Is there anything like MemoryConstrained, but for disk space? Or any way in general to restrict the disk space Export is allowed to use? I'd like the file to export if it would take less than a certain amount of disk space, but not export if it would take more. Is there any way to do this?
1 Answer
$\begingroup$
$\endgroup$
3
I would suggest the workaround to create smaller files and use the sum of
FileByteCount[]
of each file as a check while exporting.
-
1$\begingroup$ Wouldn't you want to know the size of the file before attempting to write it? I'm thinking one would want to know the amount of free space on the filesystem. $\endgroup$ Commented Aug 11, 2015 at 17:38
-
$\begingroup$ checking the space on the filesys is also possible: mathematica.stackexchange.com/questions/16804/…
StringJoin[ReadList["!dir c:\ ", Word, RecordLists -> True,WordSeparators -> {" ", ","}][[-1, 3 ;; -3]]] // ToExpression
$\endgroup$ Commented Aug 12, 2015 at 6:42 -
$\begingroup$ If you also need to have an approximate filesize, it should be good to call
ByteCount
on whatever you are exporting, as ybeltukov suggested $\endgroup$ Commented Aug 12, 2015 at 6:56
TimeConstrained
orByteCount
because both are correlated with the output size. $\endgroup$ExportString
to export individual chunks (e.g. this is the case for CSV). $\endgroup$