VBScript找到路径文件夹,然后将路径输入到文本txt文件中

时间:2017-08-01 04:22:24

标签: vbscript

我一直在尝试查找和编写一个vbscript,使我能够找到文件路径,然后将其位置插入text.txt文件

例如:

点击Find.vbs

窗口打开以搜索文件夹或驱动器

选择c:\ test folder

您确定要选择c:\ test文件夹吗?提示

单击是按钮

text.txt文件中的

单词driveselect更改为c:\ test

我发现这会打开窗口,然后让我选择一个文件,然后打开一个msgbox来显示文件名,但不会只选择一个文件夹

Set wShell=CreateObject("WScript.Shell")
Set oExec=wShell.Exec("mshta.exe ""about:<input type=file id=FILE>
<script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);</script>""")
sFileSelected = oExec.StdOut.ReadLine
wscript.echo sFileSelected

我发现有一些代码可以更改word文件中的文本,但不会更改带有输入的文本文件。

任何帮助将不胜感激。

感谢

1 个答案:

答案 0 :(得分:0)

您可以使用Excel应用程序的FileDialog选择文件夹。

Dim FolderName, msg, msgResponse

Do
    FolderName = getSelectedFolderPath
    msg = "Are you sure you want to select " & vbCrLf & FolderName & "?"
    msgResponse =  MsgBox(msg, vbYesNo,"") 
Loop Until Len(FolderName) = 0 Or msgResponse = vbYes

Function getSelectedFolderPath
    Const msoFileDialogFolderPicker = 4
    Dim xlApp
    Set xlApp = CreateObject("Excel.Application")
    With xlApp.FileDialog(msoFileDialogFolderPicker)
        .Show
        If .SelectedItems.Count > 0 Then
            getSelectedFolderPath = .SelectedItems(1)
        End If
    End With
    xlApp.Quit
End Function
相关问题