设置文件的“上次修改日期"|触摸文件(菜鸟请求) [英] Setting a file's "Last modified Date" | Touch a file (Noob-request)
问题描述
我需要对一个小代码片段的快速支持.我想触摸"一个文件,或者说更改上次修改日期".
I need some quick support for a small code-snippet. I want to "touch" a file or lets say change the "Last modified Date".
我有以下代码片段:
Touch "C:\temp\VBS", "test.txt", "1/01/2006 11:00:00 PM"
Function Touch(strDir, strFileName, DateTime)
Dim objShell, objFolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(strDir)
objFolder.Items.Item(strFileName).ModifyDate = DateTime
End Function
它有效,但我不想将文件夹和文件分别传递给函数.(C:\temp\VBS"和test.txt")我想传递 FQDN 或全名".("C:\temp\VBS\test.txt")
It works, but I don't want to pass the folder and the file separately to the function. ("C:\temp\VBS" and "test.txt") I want to pass a FQDN or "full name". ("C:\temp\VBS\test.txt")
我通过 Google 找到的所有示例都使用这种拆分技术,而且我无法自己编写 VB ...
All samples I found via Google use this split-tech and I am not able to write VB on my own ...
谢谢
推荐答案
分裂显然是由 .NameSpace 和 .Item 的不同参数引起的.给定完整的文件规范,您可以使用 FileSystemObject 的 .GetParentFolderName 和 .GetFileName 方法:
The split is obviously motivated by the different arguments to .NameSpace and .Item. Given a full file spec, you can use the .GetParentFolderName and .GetFileName methods of the FileSystemObject:
Option Explicit
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim sFSpec : sFSpec = WScript.ScriptFullName
WScript.Echo "Path", goFS.GetParentFolderName(sFSpec)
WScript.Echo "Name", goFS.GetFileName(sFSpec)
输出:
e:\work\proj\soa\42225862
cscript 42254081.vbs
Path e:\work\proj\soa\42225862
Name 42254081.vbs
这篇关于设置文件的“上次修改日期"|触摸文件(菜鸟请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!