简体   繁体   中英

Applying File Stat (struct type of stat) across all Operating Systems

I want to know how to apply file stat(struct stat) across all OS.

For example, I have a file stat of a file in Windows OS in the form of struct stat . I copied that file to a Linux OS. But now, I need to apply the file stat to Linux OS. Is there any method to use this for all OS? Do I need to convert the windows stat to some other format before applying it to Linux OS?

File Stat in the sense that I mean that Last Modified Time, File Created Time and Accessed Time etc.

Do you mean that you want the files on both systems to have the same creation timestamp, modified timestamp, etc?

Some metadata , like the timestamps, can be set for almost all operating systems. Other field can not be transferred, or need special processing. These include things like the rights of the file (read-write-execute) and user/group.

To change the timestamps on the Linux system, see the command touch if you want to do it through the command line, and the function utime if you want to do it in your own program.

Edit: After you clearing things up with your comment, you should know that the stat structure on Windows and Linux are not the same! There are more fields in the Linux stat structure, and the order is probably not the same as well. If you want to transfer this data between systems, your best bet is to create your own structure, containing the exact data you need, and have functions on each operating system that translates from/to the native stat structure.

Your question is unclear. stat is a POSIX call that accepts struct stat * and fills it in. You can't copy that filled in structure to another POSIX system and expect the format to be the same, but you can certainly invoke stat on a copy of the file under another POSIX system.

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