When using os.stat() in Python, can I assume that st_ctime is always less then or equal to st_mtime? If not, why not?
The code will always run on Linux, but if there is
Please define "less than", do you mean newer or older? You can't assume that ctime happened before mtime, but normally ctime is the same as, or after, mtime.
ctime on unix is not "create time", but "change time". mtime is updated when a file's contents are changed, but ctime is updated when file metadata is changed (which means it's updated when mtime is updated too), so it's perfectly normal for ctime to be after mtime. Here's an example:
user@ubuntu:~$ touch test
user@ubuntu:~$ chmod 600 test
user@ubuntu:~$ stat test
File: «test»
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 700h/1792d Inode: 222375 Links: 1
Access: (0600/-rw-------) Uid: ( 1000/ user) Gid: ( 1000/ user)
Access: 2011-01-03 12:35:15.945973569 +0100
Modify: 2011-01-03 12:35:15.945973569 +0100
Change: 2011-01-03 12:35:24.024998291 +0100
Also, I believe that on Windows, the ctime field actually does mean "create time", and that this is an os difference between Windows and Unix. I've read something about this online, but I'll let you do your own research on this.