我有一个stat结构,我想创建一个文件夹或文件,并希望强制它拥有与stat结构中相同的信息。
例如:
create file: test.txt
The file's last modification date is today 16.01.2014
change file's stat so that it shows:
last modified on 01.01.2050
我该怎么做?
最佳答案
如果要设置mtime/atime
字段,可以使用utime()
函数。创建文件/目录后使用它。mode
字段设置为chmod()
如果您是根用户,则使用uid/gid
设置chown()
。
如果设置字段所引用的信息(文件的数据和包含文件的目录结构),则字段size
和nlinks
将具有正确的值。
但是ino
、dev
和ctime
字段是由系统内部设置的,不能更改。不管怎样,你没有理由要设置它们。
关于c - 强制创建的文件或文件夹具有特定的统计结构,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21166620/