2017-08-01 94 views
1

我一直在試圖找到寫一個VBScript,讓我找到一個文件路徑,然後插入它的位置到文件──test.txt文件VBScript中查找路徑的文件夾,然後輸入路徑轉換成文本TXT文件

例如:

點擊Find.vbs

窗口中打開搜索文件夾或驅動

選擇C:\ test文件夾

你確定要選擇c:\ test文件夾嗎?在文件──test.txt文件

字driveselect更改爲C提示

點擊Yes按鈕

:\測試

,我發現這個打開的窗口中,然後讓我選擇文件,它然後打開一個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 

那裏是我發現改變文字文件中的文本的幾個代碼,但不包含帶有輸入的文本文件。

任何幫助將不勝感激。

謝謝

回答

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