在 Windows Vista 计算机上下载文件并根据日期重命名的脚本?
我需要每天运行一个脚本,该脚本将从固定位置下载文件,并使用适当的文件名 -YYYYMMDD-HHSS.ext 时间戳将其保存在我的计算机上。我需要该文件在特定时间的历史记录。我可以手动检查并查看更改是什么,因此不需要比较。
(我正在寻找可以为我完成此操作的在线服务,但我认为在我的计算机上本地运行的脚本就足够了)。
虽然我的机器上确实有 php,但我更喜欢它是一个纯粹的 Windows 内置解决方案,以防万一我必须(可能)将其适应其他人的系统(非技术人员)。
如果有人有类似的东西并且可以贡献代码 - 我们将不胜感激!
D
I need to daily run a script that will download a file from a fixed location and save it on my computer with an appropriate filename-YYYYMMDD-HHSS.ext timestamp. I need a historical record of what that file was at that particular time. I can manually check and see what the changes were, so compairson not needed.
(I was looking for an online service that would do this for me, but I think a locally running script on my machine would be good enough).
Although i do have php on my machine, i would prefer if its a pure windows builtin solution, just in case i have to (likely) adapt it to someone else's system (non-techies).
If someone has something like this and can contribute the code - help would be most appreciated!!
D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 Windows 脚本宿主语言轻松编写任务脚本 - VBScript或 JScript。
要从 Internet 下载文件,您可以使用
XMLHTTP
对象从服务器请求文件内容,然后使用 ADO Stream 对象将其保存到磁盘上的文件中。至于时间戳,问题在于 VBScript 和 JScript 都没有内置函数可以将日期格式化为您需要的格式,因此您必须自己编写代码来执行此操作。例如,您可以将日期拆分为多个部分,必要时填充它们,然后将它们重新连接在一起。或者您可以使用 WMI
SWbemDateTime
使用yyyymmddHHMMSS.mmmmmmsUUU
的对象日期格式,只需从中提取 yyyymmddHHMMSS 部分即可。不管怎样,这里有一个示例脚本(VBScript 格式)来说明这个想法。我将原始文件名硬编码在
strFile
变量中,因为我懒得从 URL 中提取(并且以防万一 URL 没有指定文件名,如 http://www.google.com)。如果您需要更多解释,请随时询问。
Your task can be easily scripted using Windows Script Host languages -- VBScript or JScript.
To download a file from Internet, you can use the
XMLHTTP
object to request the file contents from the server and then use the ADO Stream object to save it to a file on the disk.As for the timestamp, the problem is that neither VBScript nor JScript have built-in functions that would format the date in the format you need, so you will have to write the code for doing this yourself. For example, you could split the date into parts, pad them if necessary and concatenate them back together. Or you could use the WMI
SWbemDateTime
object that uses theyyyymmddHHMMSS.mmmmmmsUUU
date format, and simply extract theyyyymmddHHMMSS
part from it.Anyway, here's a sample script (in VBScript) that illustrates the idea. I hard-coded the original file name in the
strFile
variable, because I was too lazy to extract in from the URL (and also in case the URL doesn't specify the file name, like in http://www.google.com).Feel free to ask if you need more explanation.
像 Mercurial 这样的版本控制系统可以为您完成此操作,而无需重命名文件。该脚本可能很简单(获取 wget 此处 和 Mercurial 此处):
一个很好的功能是,除非文件内容发生更改,否则不会发生提交。
要查看历史记录,请使用 hg log 或 TortoiseHg(shell 扩展)。
A version control system like Mercurial can do this for you without you having to rename the file. The script might be as simple as (get wget here and Mercurial here):
A nice feature of this is that the commit won't happen unless the file's contents have changed.
To see the history, use hg log or TortoiseHg (a shell extension).
建立在:
http://blog.netnerds.net /2007/01/vbscript-download-and-save-a-binary-file/
和
http://developernotes.thomaspowell.com/2008/06/vbscript-to-convert-timestamp-to.php
Build up on:
http://blog.netnerds.net/2007/01/vbscript-download-and-save-a-binary-file/
and
http://developernotes.thomaspowell.com/2008/06/vbscript-to-convert-timestamp-to.php