如何在Windows中获取*更改*文件时间? [英] How do I get *change* file time in Windows?

查看:276
本文介绍了如何在Windows中获取*更改*文件时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用FreeNAS CIFS与Windows共享(从 FreeNAS)同步文件),并遇到一个问题,即robocopy.exe认为某些文件需要每次运行robocopy.exe(/ COPY:DAT)时都要复制一次。

我最喜欢的文件管理工具Far Manager告诉我更改时间是不同的:
$ b 文件在Windows上的时间:



在FreeNAS(ZFS)支持的CIFS份额上的文件时间:

我完全正确地认为更改时间已经丢失,我很乐意重置Windows驱动器上的更改时间,但是我可以Python的os.stat(filename)返回st_atime,st_mtime和st_ctime,而且我测试过,这个元组的值是相等的Windows和FreeNAS之间的值。大概更改时间是不存在的。

Windows API也只给出了3个数字(创建,最后访问和最后写入),而不是更改时间:
http:// msdn显然,无论是robocopy.exe还是其他版本的软件,远管理器以某种方式从系统中获得4个值。我真的想避免分解他们,希望在这里得到答案。我如何获得和设置更改时间?



任何解决方案都可以(Python,C ++,WinAPI,可以操作的外部命令行工具等)。

远用NtQueryInformationFile获取时间和NtSetInformationFile来设置它们,而FILE_BASIC_INFORMATION结构包含所有4次,包括更改时间。

QueryInformationFile文档:
http://msdn.microsoft.com/en- (zwQueryInformationFile)

SetInformationFile文档:
http://msdn.microsoft.com/en-us/library /windows/hardware/ff567096(v=vs.85).aspx (ZwSetInformationFile)

FILE_BASIC_INFORMATION文档: http://msdn.microsoft.com/zh-cn/library/windows/硬件/ ff545762(v = vs.85).aspx

  typedef struct _FILE_BASIC_INFORMATION {
LARGE _INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime; //< ---赢!
ULONG FileAttributes;
} FILE_BASIC_INFORMATION,* PFILE_BASIC_INFORMATION;

不知道Python是否有很好的包装,但这已经够好了,我可以自己写包装。


I am trying to use FreeNAS CIFS share with Windows (synchronizing files from Windows to FreeNAS) and hit a problem that robocopy.exe thinks that some files need to be copied again every time I run robocopy.exe (/COPY:DAT).

My favorite file management tool, Far Manager, tells me that "Change time" is different:

File times on Windows:

File times on CIFS share backed by FreeNAS (ZFS):

I am perfectly fine with the fact that "change time" is lost, and I'd be happy to reset change time on the Windows drive, but I can't find how I can do that programmatically.

Python's os.stat(filename) returns st_atime, st_mtime and st_ctime, and, I've tested, this tuple has equal values between Windows and FreeNAS. Presumably "change time" isn't there.

Windows API also gives only 3 numbers (creation, last access and last write) but not "change time": http://msdn.microsoft.com/en-us/library/windows/desktop/ms724320(v=vs.85).aspx

Apparently both robocopy.exe and Far Manager somehow get 4 values from the system. I'd really like to avoid disassembling them, hoping to get an answer here. How do I get and set "change time"?

Any solution will do (Python, C++, WinAPI, external command line tools that can manipulate that, etc).

解决方案

OK, I seem to have figured it out, thanks to cocarin for pointing to Far sources. Far uses NtQueryInformationFile to get times and NtSetInformationFile to set them, and FILE_BASIC_INFORMATION structure contains all 4 times, including change time.

QueryInformationFile docs: http://msdn.microsoft.com/en-us/library/windows/hardware/ff567052(v=vs.85).aspx (ZwQueryInformationFile)

SetInformationFile docs: http://msdn.microsoft.com/en-us/library/windows/hardware/ff567096(v=vs.85).aspx (ZwSetInformationFile)

FILE_BASIC_INFORMATION docs: http://msdn.microsoft.com/en-us/library/windows/hardware/ff545762(v=vs.85).aspx

typedef struct _FILE_BASIC_INFORMATION {
  LARGE_INTEGER CreationTime;
  LARGE_INTEGER LastAccessTime;
  LARGE_INTEGER LastWriteTime;
  LARGE_INTEGER ChangeTime;        // <--- win!
  ULONG         FileAttributes;
} FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;

Not sure if there are any nice wrappers for Python but this is good enough, I can write my own wrapper.

这篇关于如何在Windows中获取*更改*文件时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆