如何创建文本文件并在 vbscript 中写入 [英] How to create text file and write to it in vbscript

查看:49
本文介绍了如何创建文本文件并在 vbscript 中写入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本可以定位机器上的所有访问文件:

I have the following script which locates all access files on a machine:

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = 'mdb' OR Extension = 'ldb'")

For Each objFile in colFiles
    Wscript.Echo objFile.Name
Next

我对 vbscript 非常业余.我如何让脚本将每一行写入名为Results.txt"的文本文件,而不是回显到对话框?

I'm very amateur when it comes to vbscript. Instead of Echoing to a dialog box, how do I have the script write each line out to a text file called "Results.txt"?

另外,作为奖励,我如何包含每个 Access 文件的修改日期?

Also, as a bonus, how do I include the date modified of each Access file?

推荐答案

vbscript 创建并写入文本文件" 之类的简单 Google 搜索将为您提供有关如何解决此问题的海量信息.无论如何,这是最简单的方法,可以让您开始.

Simple Google search like "vbscript create and write to text file" will give you ocean of information on how to tackle this. Anyway here is simplest one to give you kick start.

'~ Create a FileSystemObject
Set objFSO=CreateObject("Scripting.FileSystemObject")

'~ Provide file path
outFile="YouFolderPath\Results.txt"

'~ Setting up file to write
Set objFile = objFSO.CreateTextFile(outFile,True)


strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
    ("Select * from CIM_DataFile Where Extension = 'mdb' OR Extension = 'ldb'")

For Each obj_File in colFiles
    'Wscript.Echo objFile.Name  'Commented out

    '~ Write to file
    objFile.WriteLine obj_File.Name
Next

'~ Close the file
objFile.Close

这篇关于如何创建文本文件并在 vbscript 中写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆