Vbscript 使用vbs(access)打开、保存和关闭文本文件
问题是如何从vbscript打开、保存和关闭文本文件 我需要打开一个特定的txt文件,保存它,然后关闭文本文件 我可以通过以下方式打开文件:Vbscript 使用vbs(access)打开、保存和关闭文本文件,vbscript,sendkeys,Vbscript,Sendkeys,问题是如何从vbscript打开、保存和关闭文本文件 我需要打开一个特定的txt文件,保存它,然后关闭文本文件 我可以通过以下方式打开文件: Dim Objecttxt Set Objecttxt = CreateObject("WScript.Shell") Objecttxt.Run "notepad.exe d:\text.txt" Objecttxt.SendKeys "^(s)", True 然后我尝试使用以下命令来命令txt文件: Dim Objecttxt Set Object
Dim Objecttxt
Set Objecttxt = CreateObject("WScript.Shell")
Objecttxt.Run "notepad.exe d:\text.txt"
Objecttxt.SendKeys "^(s)", True
然后我尝试使用以下命令来命令txt文件:
Dim Objecttxt
Set Objecttxt = CreateObject("WScript.Shell")
Objecttxt.Run "notepad.exe d:\text.txt"
Objecttxt.SendKeys "^(s)", True
及
但是焦点没有设置到记事本编辑器
我还添加了一行:
Objecttxt.AppActivate“Text.txt-Kladblok”,800
但这似乎没有影响。
不接受WScript.Sleep 800命令(access 2007)
谁能告诉我:
- 这条路对吗
- 这种方法如何工作
谢谢,例如,我正在将.png文件更改为.jpg
Option Explicit
' Change the Extension you want to Replace
Const CHANGE_FROM = ".png"
Const CHANGE_TO = ".jpg"
' Var Declaration - Don't Change
Dim srcFolder
Dim objFSO, objFolder, oFolder
Dim colFiles
' Set the Source Folder to Begin With or you can dynamically find this if this is being used on multiple computers
srcFolder = "C:\Temp\Files"
' Object Sets - Don't Change
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(srcFolder)
Set colFiles = objFolder.Files
' Changes Files Extensions in Source Folder
ChangeExtension colFiles
' Change the Extension for Each Sub Folder in the Source Folder
GetFilesFromSubFolders objFolder
描述:Sub将递归检查每个文件夹中的子文件夹
对于每个子文件夹,它将提取文件并使用ChangeExtension
更改文件扩展名的步骤
输入:根文件夹对象
输出:每个子文件夹的递归调用-更改文件扩展名
--- Subs ---
Sub GetFilesFromSubFolders(objRootFolder)
Dim oSubFolders, oSubFol
Dim colSubFolFiles
' Get the Sub Folders of the Root Folder
Set oSubFolders = objRootFolder.SubFolders
' Check that Folder has Sub Folders
If oSubFolders.Count > 0 Then
' For Each Sub Folder Call Recursevlly
For Each oSubFol In oSubFolders
GetFilesFromSubFolders oSubFol
Next
End If
' Get the Files in the folder
Set colSubFolFiles = objRootFolder.Files
' Change Files Extensions in Folder
ChangeExtension colSubFolFiles
End Sub
Sub ChangeExtension(collectionSet)
' Description : Sub will Change the Extension
' for Each File that has the Requested Extension
' Input : Collection Set Object of Files
' Output : Changes the File Extension
Dim objFile
' For Each File in the Files Collection
For Each objFile In collectionSet
' Check if File has the Requested Extension
If InStr(objFile.Name,CHANGE_FROM) Then
' Checge the Extension
objFile.Name = Replace(objFile.Name,CHANGE_FROM,CHANGE_TO)
End If
Next
End Sub
如果不做任何更改,为什么要保存它?我只想通过保存文件来打开并保存它以获得正确的格式。我也在尝试使用set ObjFile open and Close命令,但它只在发生更改时保存文件。如果您接受我的回答代码:Dim strMCP1Name作为字符串Dim ObjFso作为对象Dim ObjFile作为对象strMCP1Name=CurrentProject.Path&“\”location&“\tst.csv”set ObjFso=CreateObject,您会帮我很多忙(“Scripting.FileSystemObject”)设置ObjFile=ObjFso.OpenTextFile(strMCP1Name,8,-1)“打开文件集”ObjFile.WriteLine(“;”)“将一些数据写入文件ObjFile.Close”关闭文件--------问题是,当我向文件添加一行时,Close命令也是save命令。当我删除line add命令时,文件中没有任何更改,因此file Close命令不会保存文件。感谢重播,我没有任何enoug字符。有因此,我需要的是一个命令“save”,这样文件中的名称和数据就必须保持不变。只有通过保存文件,数据的格式才会设置为正确的格式。为什么需要运行命令才能完成此操作?如果您只想更改文件的扩展名,则此代码可以工作。