VBScript 读取或者修改文件的属性信息

!本文可能 超过1年没有更新,今后内容也许不会被维护或者支持,部分内容可能具有时效性,涉及技术细节或者软件使用方面,本人不保证相应的兼容和可操作性。

今天在Scripting Guy上看到一段有趣的脚本即获取和设置一个文件的属性,何为文件属性?当你对一个文件右击查看属性并切换到详细信息时,你就会发现这些信息:

Word文件属性.png

下面主要介绍如何利用脚本读取或者修改这些信息。谈到脚本的文件操作,大家首先想到的恐怕是FSO(FileSystemObject)组件吧,但是很遗憾FSO组件不支持对这些信息的操作,脚本专家的《如何向文档的“备注”字段写入信息?》提供了一个微软的COM组件Microsoft Developer Support OLE File Property Reader 2.1 Sample (KB 224351)即Dsofile可以帮我们实现这个需求,安装解压后惊喜的发现其提供了C++源代码和VB6和VB7的演示代码,看来可以好好研究一番了,哦,对了,我把脚本专家上的那段代码贴这儿备忘吧:-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Set objPropertyReader = CreateObject("DSOleFile.PropertyReader")
Set objDocument = objPropertyReader.GetDocumentProperties _
    ("C:\Scripts\Test.doc")
Wscript.Echo "App name: " & objDocument.AppName
Wscript.Echo "Author: " & objDocument.Author
Wscript.Echo "Byte count: " & objDocument.ByteCount
Wscript.Echo "Category: " & objDocument.Category
Wscript.Echo "Character count: " & objDocument.CharacterCount
Wscript.Echo "Character count with spaces: " &_
 objDocument.CharacterCountWithSpaces
Wscript.Echo "CLSID: " & objDocument.CLSID
Wscript.Echo "Comments: " & objDocument.Comments
Wscript.Echo "Company: " & objDocument.Company
Set colCustomProperties = objDocument.CustomProperties
For Each strProperty in colCustomProperties
    Wscript.Echo vbTab & strProperty.Name & ": " &_
 strProperty.Value
Next
Wscript.Echo "Date created: " & objDocument.DateCreated
Wscript.Echo "Date last printed: " & objDocument.DateLastPrinted
Wscript.Echo "Date last saved: " & objDocument.DateLastSaved
Wscript.Echo "Has macros: " & objDocument.HasMacros
Wscript.Echo "Hidden slides: " & objDocument.HiddenSlides
Wscript.Echo "Icon: " & objDocument.Icon
Wscript.Echo "Is read only: " & objDocument.IsReadOnly
Wscript.Echo "Keywords" & objDocument.Keywords
Wscript.Echo "Last edited by: " & objDocument.LastEditedBy
Wscript.Echo "Line count: " & objDocument.LineCount
Wscript.Echo "Location: " & objDocument.Location
Wscript.Echo "Manager: " & objDocument.Manager
Wscript.Echo "Multimedia clips: " & objDocument.MultimediaClips
Wscript.Echo "Name: " & objDocument.Name
Wscript.Echo "Page count: " & objDocument.PageCount
Wscript.Echo "Paragraph count: " & objDocument.ParagraphCount
Wscript.Echo "Presentation format: " & objDocument.PresentationFormat
Wscript.Echo "Presentation notes: " & objDocument.PresentationNotes
Wscript.Echo "ProgID: " & objDocument.ProgID
Wscript.Echo "Revision number: " & objDocument.RevisionNumber
Wscript.Echo "Slide count: " & objDocument.SlideCount
Wscript.Echo "Subject: " & objDocument.Subject
Wscript.Echo "Template: " & objDocument.Template
Wscript.Echo "Thumbnail: " & objDocument.Thumbnail
Wscript.Echo "Title: " & objDocument.Title
Wscript.Echo "Version: " & objDocument.Version
Wscript.Echo "Word count: " & objDocument.WordCount
若无特别说明,本网站文章均为原创,原则上这些文章不允许转载,但是如果阁下是出于研究学习目的可以转载到阁下的个人博客或者主页,转载遵循创作共同性“署名-非商业性使用-相同方式共享”原则,请转载时注明作者出处谢绝商业性、非署名、采集站、垃圾站或者纯粹为了流量的转载。谢谢合作!

请稍后...

发表评论

电子邮件地址不会被公开。 必填项已用*标注