FileSetTime

首页  后退  前进

FileSetTime
down2

FileSetTime

设置一或多个文件的时间戳.

 

FileSetTime ( "file pattern", "time" [, type = 0 [, recurse = 0]] )

参数

file pattern

目标文件的完整路径文件名, 例如: C:\*.au3, C:\Dir. (接受通配符 * 和 ? - 见备注)

time

新时间格式 "YYYYMMDDHHMMSS" (年月日时分秒, 24小时制). 如为空 "", 则使用当前时间.

type

[可选] 更改时间戳类型:

 $FT_MODIFIED (0) = 最后修改时间(默认)

 $FT_CREATED (1) = 创建时间

 $FT_ACCESSED (2) = 最后访问时间

 

常量定义在 FileConstants.au3

recurse

[可选]

   $FT_NONRECURSIVE (0) - 不递归 (默认).

   $FT_RECURSIVE (1) - 目录递归进入.

 

常量定义在 FileConstants.au3

返回值

成功:

返回 1.

失败:

返回 0, 修改时间戳错误.

备注

有关通配符的论述参考 FileFindFirstFile().

 

如果设置日期早于 1980-01-01, 则没有任何效果.

如果修改只读文件的时间戳将返回一个错误.

 

函数示例

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Example()
Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = _WinAPI_GetTempFileName(@TempDir)
    ; Create a temporary file to read data from.
    If Not FileWrite($sFilePath, "This is an example of using FileSetTime.") Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the temporary file.")
        Return False
    EndIf
    ; Set the modified timestamp of the file to 1st Nov 2003 and use the current time.
    Local $iFileSetTime = FileSetTime($sFilePath, "20031101", $FT_MODIFIED)
    ; Display the modified timestamp of the file and return as a string in the format YYYYMMDDHHMMSS.
    If $iFileSetTime Then
        MsgBox($MB_SYSTEMMODAL, "", "Timestamp:" & @CRLF & FileGetTime($sFilePath, $FT_MODIFIED, 1))
    Else
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst setting the timestamp of the file.")
    EndIf
    ; Delete the temporary file.
    FileDelete($sFilePath)
EndFunc   ;==>Example

----------------------------------------

 

该函数可以通过命令 exect 调用

参见:

FileGetTime, FileSetAttrib

例子
copy

exect=FileSetTime('C:\Test\*.txt','20140101') ;; 在2014年1月1日的测试文件夹更改日期中设置所有txt文件

 

exect=FileSetTime('C:\Test\test.txt','20140101') ;; 将文件test.txt设置为2014年1月1日更改的日期

up2

tcimage © Аверин Андрей для Total Commander Image Averin-And@yandex.ru