File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55使用Get-ChildItem获得FileInfo对象,直接给其对应属性赋值即可,时间格式为` 2018-08-25 15:23:36 ` ,如果选用当前时间可直接使用命令` date ` 代替时间。
66
77``` powershell
8- PS C:\Users\92363> $s=Get-ChildItem Desktop\ca_setup.exe
9- PS C:\Users\92363> $s
8+ PS C:\Users\HUAWEI\Desktop> Get-ItemProperty -Path .\1.jsp | fl
109
1110
12- 目录: C:\Users\92363\Desktop
1311
1412
15- Mode LastWriteTime Length Name
16- ---- ------------- ------ ----
17- -a---- 2016/7/9 0:00 8244106 ca_setup.exe
13+ Name : 1.jsp
14+ Length : 2598
15+ CreationTime : 2020/8/24 14:29:10
16+ LastWriteTime : 2020/8/24 14:29:10
17+ LastAccessTime : 2020/11/6 14:54:12
18+ Mode : -a----
19+ LinkType :
20+ Target : {}
21+ VersionInfo : File: C:\Users\HUAWEI\Desktop\1.jsp
22+ InternalName:
23+ OriginalFilename:
24+ FileVersion:
25+ FileDescription:
26+ Product:
27+ ProductVersion:
28+ Debug: False
29+ Patched: False
30+ PreRelease: False
31+ PrivateBuild: False
32+ SpecialBuild: False
33+ Language:
1834
19- PS C:\Users\92363> $s.CreationTime
20- PS C:\Users\92363> $s.LastAccessTime=date
21- PS C:\Users\92363> $s.LastAccessTime="2018-08-25 15:23:36"
22- PS C:\Users\92363> $s.LastWriteTime
35+
36+
37+
38+ PS C:\Users\HUAWEI\Desktop> Set-ItemProperty -Path .\1.jsp -Name CreationTime -Value '2020年11月6日 14:56:25'
39+ PS C:\Users\HUAWEI\Desktop> Get-ItemProperty -Path .\1.jsp | fl
40+
41+
42+ 目录: C:\Users\HUAWEI\Desktop
43+
44+
45+
46+ Name : 1.jsp
47+ Length : 2598
48+ CreationTime : 2020/11/6 14:56:25
49+ LastWriteTime : 2020/8/24 14:29:10
50+ LastAccessTime : 2020/11/6 14:57:36
51+ Mode : -a----
52+ LinkType :
53+ Target : {}
54+ VersionInfo : File: C:\Users\HUAWEI\Desktop\1.jsp
55+ InternalName:
56+ OriginalFilename:
57+ FileVersion:
58+ FileDescription:
59+ Product:
60+ ProductVersion:
61+ Debug: False
62+ Patched: False
63+ PreRelease: False
64+ PrivateBuild: False
65+ SpecialBuild: False
66+ Language:
67+
68+
69+
70+
71+ PS C:\Users\HUAWEI\Desktop>
2372```
2473一个问题值得思考:我们只是对powershell中的一个变量赋值,这顶多改变内存中的值,它怎么就同步到磁盘将文件时间戳永久改变了呢?一开始我在网上看到这中操作的时候,我是试都不想试,但最终事实摆在眼前,不得不服这种骚操作。
2574
You can’t perform that action at this time.
0 commit comments