因此,问题是:我有一些普通文件,它们被放入一个ZIP文件中(有关ZIP的详细信息,请参阅下面的内容)。然后我解压缩它们(有关所使用的工具的详细信息,请参阅下面),并恢复文件。恢复文件的日期,就像使用的ZIP/UNZIP工具中的标准一样。在使用DIR或Windows资源管理器进行查询时,所涉及的文件在被ZIP/UNZIP进程处理之前具有与它们相同的日期。
所以,一切都好。
但是,我使用XCOPY /D命令,进一步操作磁盘上这些文件的不同副本.XCOPY说:一个文件比另一个文件更新。考虑到日期,小时,直到分钟是一样的。区别就在于一个较小的实体,比如秒?
所有涉及的磁盘都有NTFS文件系统。
示例:
C:\my>dir C:\windows\Background_mycomputer.cmd C:\my\directory\Background_mycomputer.cmd
Volume in drive C is mycomputerC
Volume Serial Number is 1234-5678
Directory of C:\windows
31/12/2014 19:50 51 Background_mycomputer.cmd
1 File(s) 51 bytes
Directory of C:\my\directory
31/12/2014 19:50 51 Background_mycomputer.cmd
1 File(s) 51 bytes
0 Dir(s) 33.655.316.480 bytes free
C:\my>xcopy C:\windows\Background_mycomputer.cmd C:\my\directory\Background_mycomputer.cmd /D
Overwrite C:\my\directory\Background_mycomputer.cmd (Yes/No/All)? y
C:\windows\Background_mycomputer.cmd
1 File(s) copied
C:\my>xcopy C:\my\directory\Background_mycomputer.cmd C:\windows\Background_mycomputer.cmd /D
0 File(s) copied
C:\my>xcopy C:\windows\Background_mycomputer.cmd C:\my\directory\Background_mycomputer.cmd /D
0 File(s) copied
C:\my>unzip -v
UnZip 6.00 of 20 April 2009, by Info-ZIP. Maintained by C. Spieler. Send
bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
Latest sources and executables are at ftp://ftp.info-zip.org/pub/infozip/ ;
see ftp://ftp.info-zip.org/pub/infozip/UnZip.html for other sites.
Compiled with Microsoft C 13.10 (Visual C++ 7.1) for
Windows 9x / Windows NT/2K/XP/2K3 (32-bit) on Apr 20 2009.
UnZip special compilation options:
ASM_CRC
COPYRIGHT_CLEAN (PKZIP 0.9x unreducing method not supported)
NTSD_EAS
SET_DIR_ATTRIB
TIMESTAMP
UNIXBACKUP
USE_EF_UT_TIME
USE_UNSHRINK (PKZIP/Zip 1.x unshrinking method supported)
USE_DEFLATE64 (PKZIP 4.x Deflate64(tm) supported)
UNICODE_SUPPORT [wide-chars] (handle UTF-8 paths)
MBCS-support (multibyte character support, MB_CUR_MAX = 1)
LARGE_FILE_SUPPORT (large files over 2 GiB supported)
ZIP64_SUPPORT (archives using Zip64 for large files supported)
USE_BZIP2 (PKZIP 4.6+, using bzip2 lib version 1.0.5, 10-Dec-2007)
VMS_TEXT_CONV
[decryption, version 2.11 of 05 Jan 2007]
UnZip and ZipInfo environment options:
UNZIP: [none]
UNZIPOPT: [none]
ZIPINFO: [none]
ZIPINFOOPT: [none]
C:\my>ver
Microsoft Windows [Version 6.1.7601]
C:\my>zip -?
Copyright (c) 1990-2006 Info-ZIP - Type 'zip "-L"' for software license.
Zip 2.32 (June 19th 2006). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
-f freshen: only changed files -u update: only changed or new files
-d delete entries in zipfile -m move into zipfile (delete files)
-r recurse into directories -j junk (don't record) directory names
-0 store only -l convert LF to CR LF (-ll CR LF to LF)
-1 compress faster -9 compress better
-q quiet operation -v verbose operation/print version info
-c add one-line comments -z add zipfile comment
-@ read names from stdin -o make zipfile as old as latest entry
-x exclude the following names -i include only the following names
-F fix zipfile (-FF try harder) -D do not add directory entries
-A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)
-T test zipfile integrity -X eXclude eXtra file attributes
-! use privileges (if granted) to obtain all aspects of WinNT security
-R PKZIP recursion (see manual)
-$ include volume label -S include system and hidden files
-e encrypt -n don't compress these suffixes
C:\my>问题:我不希望XCOPY在我知道它们无效的地方进行更新,因为时间格式做错了什么。我该怎么防止呢?
在我看来,涉及的内容不同,是XCOPY,非常具体的ZIP和解压缩,以及NTFS文件系统。哪一个做错了什么?
我必须强调的是,除了ZIP和UNZIP之外,还没有对文件进行其他更改,比如更改1个文件,然后在不到60秒的时间内对另一个文件进行更改。
在测试的时刻,显示的时间不是当前的时间,也不接近它。没有文件正在调整当前时间,时间指的是所讨论的文件的最后一次更改,这可能是过去的任何时候。在这种情况下,这是在一天后,但它可以是任何东西。
发布于 2018-04-30 23:07:30
我注意到了Raymond在编写Powershell脚本(GitHub链路)以使用System.IO.Compression和System.IO.Compression.FileSystem库刷新zip存档时所描述的特殊行为。
有趣的是,Zip档案可以用相同的元数据(名称、相对路径、修改日期)存储同一文件的多个副本。在Windows资源管理器中提取文件的第二个副本将失败,因为该文件已经存在。
当试图阻止文件重新压缩时,我检查了相对路径和日期,并注意到LastWriteTime中存在最多2秒的差异。这一解决办法弥补了精确度的损失:
$AlreadyArchivedFile = ($WriteArchive.Entries | Where-Object {#zip will store multiple copies of the exact same file - prevent this by checking if already archived.
(($_.FullName -eq $RelativePath) -and ($_.Length -eq $File.Length) ) -and
([math]::Abs(($_.LastWriteTime.UtcDateTime - $File.LastWriteTimeUtc).Seconds) -le 2) #ZipFileExtensions timestamps are only precise within 2 seconds.
}) 另外,IsDaylightSavingTime标志没有存储在Zip存档中。因此,当解压缩文件比原始存档文件更新一个小时时,我感到很惊讶。我试过几次,每次压缩和提取文件时,提取的文件的时间戳都会增加一个小时。
下面是一个非常糟糕的解决方案,它将归档文件时间缩短一个小时,以使原始源文件和提取的文件时间戳保持一致:
If($File.LastWriteTime.IsDaylightSavingTime() -and $ArchivedFile){#HACK: fix for buggy date - adds an hour inside archive when the zipped file was created during PDT (files created during PST are not affected).
$entry = $WriteArchive.GetEntry($RelativePath)
$entry.LastWriteTime = ($File.LastWriteTime.ToLocalTime() - (New-TimeSpan -Hours 1))
}也许有更好的方法来处理这件事。不幸的是,我不知道如何在.Zip存档中存储文件的夏令储蓄指示符,而且这些信息都丢失了。
https://stackoverflow.com/questions/27731683
复制相似问题