Vbscript 浏览文件夹中的文件

Vbscript 浏览文件夹中的文件,vbscript,hta,Vbscript,Hta,我正在用vbs构建一个小型hta。它所做的是浏览文件夹并通过单击第一个按钮拾取文件夹或文件,然后根据文件类型或文件夹名称复制并粘贴到选定位置 我需要“浏览每个文件夹中的文件”的帮助,到目前为止,我只让“文件夹浏览器”工作。有没有一种方法可以让我同时浏览文件夹和文件,根据需要选择文件夹或文件 <html> <head> <Title>File Copy </Title> <style> img.exco { position:absolu

我正在用vbs构建一个小型hta。它所做的是浏览文件夹并通过单击第一个按钮拾取文件夹或文件,然后根据文件类型或文件夹名称复制并粘贴到选定位置

我需要“浏览每个文件夹中的文件”的帮助,到目前为止,我只让“文件夹浏览器”工作。有没有一种方法可以让我同时浏览文件夹和文件,根据需要选择文件夹或文件

<html>
<head>
<Title>File Copy </Title>
<style>
img.exco
{
position:absolute;
bottom:10px;
right:10px
}
</style>
<!--Put this sub here to avoid resize flickering.-->
<script language = "VBScript">
 sub DoResize
    'resize   
    window.resizeTo 690,350
    screenWidth = Document.ParentWindow.Screen.AvailWidth
    screenHeight = Document.ParentWindow.Screen.AvailHeight
    posLeft = (screenWidth - 700) / 2
    posTop = (screenHeight - 430) / 2     
    'move to centerscreen
    window.moveTo posLeft, posTop

  end sub

DoResize()
</script>

<HTA:APPLICATION ID=""
   applicationName=""
   version="1.1"
    BORDER="thin"
    BORDERSTYLE="static"
    CAPTION="Yes"
    CONTEXTMENU="no"
    ICON="C:\icon\32x32.ico"
    INNERBORDER="no"
    MAXIMIZEBUTTON="no"
    MINIMIZEBUTTON="no"
    NAVIGATABLE="no"
    SCROLL="no"
    SCROLLFLAT="no"
    SELECTION="no"
    SHOWINTASKBAR="yes"
    SINGLEINSTANCE="yes"
    SYSMENU="yes"
    WINDOWSTATE="normal" 
>

<script language = "VBScript">


Sub BrowseSource_OnClick()
    strStartDir = "C:\work"
    Copy_To_PC.txtFile.value = PickFolder(strStartDir)
End Sub 

Function PickFolder(strStartDir)
Dim SA, F
Set SA = CreateObject("Shell.Application")
Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
If (Not F Is Nothing) Then
  PickFolder = F.Items.Item.path
End If
Set F = Nothing
Set SA = Nothing
End Function 

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Sub RunScripts_OnClick()
    Copy
    Paste
    OpenWord

End Sub

Sub Copy

End Sub

Sub Paste

            msgBox "Copy Success!" 


End Sub

Sub OpenWord 

End Sub

</script>

</head>
<body>
<p><b><font size="4">Please select the file.</font></b></p>
<form name="Copy_To_PC">
<input type = "text" name = "txtFile" size="100" />
<input type = "button" value = "File Source" Name="BrowseSource">
<input type="button" value="Copy and Paste" name="RunScripts">

</form>


</body>
</html>

文件副本
行政长官
{
位置:绝对位置;
底部:10px;
右:10px
}
亚多里斯
“调整大小
window.resizeTo 690350
screenWidth=Document.ParentWindow.Screen.AvailWidth
屏幕高度=Document.ParentWindow.Screen.AvailHeight
posLeft=(屏幕宽度-700)/2
posTop=(屏幕高度-430)/2
'移动到中心屏幕
window.movetoposleft,posTop
端接头
DoResize()
子浏览器源_OnClick()
strStartDir=“C:\work”
将_复制到_PC.txtFile.value=PickFolder(strStartDir)
端接头
函数PickFolder(strStartDir)
Dim SA,F
Set SA=CreateObject(“Shell.Application”)
设置F=SA.BrowseForFolder(0,“选择文件夹”,0,strStartDir)
如果(不是F什么都不是)那么
PickFolder=F.Items.Item.path
如果结束
设置F=无
设置SA=无
端函数
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
子运行脚本\u OnClick()
复制
粘贴
开放词
端接头
子副本
端接头
子粘贴
msgBox“复制成功!”
端接头
次开放字
端接头
请选择该文件


我与您分享此功能可能会对您有所帮助

浏览文件.vbs

   '************************************************************************************** 
    ' GetFileDlg() And GetFileDlgBar() by omen999 - may 2014 - http://omen999.developpez.com
    ' Universal Browse for files function  
    ' compatibility : all versions windows and IE - supports start folder, filters and title
    ' note : the global size of the parameters cannot exceed 191 chars for GetFileDlg and 227 chars for GetFileDlgBar
    '**************************************************************************************
    Function GetFileDlg(sIniDir,sFilter,sTitle)
     GetFileDlg=CreateObject("WScript.Shell").Exec("mshta.exe ""about:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg('" & sIniDir & "',null,'" & sFilter & "','" & sTitle & "')));close();}</script><hta:application showintaskbar=no />""").StdOut.ReadAll
    End Function

    Function GetFileDlgBar(sIniDir,sFilter,sTitle)
     GetFileDlgBar=CreateObject("WScript.Shell").Exec("mshta.exe ""about:<object id=d classid=clsid:3050f4e1-98b5-11cf-bb82-00aa00bdce0b></object><script>moveTo(0,-9999);function window.onload(){var p=/[^\0]*/;new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(p.exec(d.object.openfiledlg('" & sIniDir & "',null,'" & sFilter & "','" & sTitle & "')));close();}</script>""").StdOut.ReadAll
    End Function

    ' sample test
    sIniDir = "C:\Windows\Fonts\*"
    sFilter = "All files (*.*)|*.*|Microsoft Word (*.doc;*.docx)|*.doc;*.docx|Adobe pdf (*.pdf)|*.pdf|"
    sTitle = "GetFileDlg by omen999 2014 - omen999.developpez.com"

    ' (sIniDir + sFilter + sTitle) size doesn't exceed 191 chars (227 for GetFileDlgBar)
    ' MsgBox Len(Replace(sIniDir,"\","\\")) + Len(sFilter) + Len(sTitle)

    ' sIniDir must be conformed to the javascript syntax
    rep = GetFileDlg(Replace(sIniDir,"\","\\"),sFilter,sTitle)
    MsgBox rep & vbcrlf & Len(rep)
”***************************************************************************************************************************************************************************
'GetFileDlg()和GetFileDlgBar(),截止日期:999年-2014年5月-http://omen999.developpez.com
'通用文件浏览功能
'兼容性:所有windows和IE版本-支持开始文件夹、筛选器和标题
'注意:参数的全局大小对于GetFileDlg不能超过191个字符,对于GetFileDlgBar不能超过227个字符
'**************************************************************************************
函数GetFileDlg(sIniDir、sFilter、sTitle)
GetFileDlg=CreateObject(“WScript.Shell”).Exec(“mshta.exe”关于:moveTo(0,-9999);函数窗口.onload(){var p=/[^\0]*/;新ActiveXObject('Scripting.FileSystemObject')。GetStandardStream(1)。Write(p.Exec(d.object.openfiledlg('sIniDir&',null,'sFilter&','sTitle&'));close();}')。StdOut.ReadAll
端函数
函数GetFileDlgBar(sIniDir、sFilter、sTitle)
GetFileDlgBar=CreateObject(“WScript.Shell”).Exec(“mshta.exe”关于:moveTo(0,-9999);函数窗口.onload(){var p=/[^\0]*/;新ActiveXObject('Scripting.FileSystemObject')。GetStandardStream(1)。Write(p.Exec(d.object.openfiledlg('sIniDir&'null','sFilter&','sTitle&');close();}')。StdOut.ReadAll
端函数
"抽样检验",
sIniDir=“C:\Windows\Fonts\*”
sFilter=“所有文件(*.*)|*.*Microsoft Word(*.doc;*.docx)|*.doc;*.docx | Adobe pdf(*.pdf)|*.pdf |”
sTitle=“GetFileDlg by omen999 2014-omen999.developpez.com”
'(sIniDir+sFilter+sTitle)大小不超过191个字符(GetFileDlgBar为227个字符)
'MsgBox Len(替换(sIniDir,“\”,“\\”))+Len(sFilter)+Len(sTitle)
'sIniDir必须符合javascript语法
rep=GetFileDlg(替换(sIniDir,“\”,“\\”),sFilter,sTitle)
MsgBox代表、vbcrlf和Len(代表)

尝试以下简单方法:

<html>
<HTA:APPLICATION ID=""
applicationName=""
version="1.1"
BORDER="thin"
BORDERSTYLE="static"
CAPTION="Yes"
CONTEXTMENU="no"
ICON="C:\icon\32x32.ico"
INNERBORDER="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
NAVIGATABLE="no"
SCROLL="no"
SCROLLFLAT="no"
SELECTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
>
<head>
<Title>File Copy </Title>
<style>
img.exco
{
position:absolute;
bottom:10px;
right:10px
}
</style>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<!--Put this sub here to avoid resize flickering.-->
<script language = "VBScript">
Call DoResize()
'***********************************************************************
sub DoResize
'resize
    window.resizeTo 690,350
    screenWidth = Document.ParentWindow.Screen.AvailWidth
    screenHeight = Document.ParentWindow.Screen.AvailHeight
    posLeft = (screenWidth - 700) / 2
    posTop = (screenHeight - 430) / 2
'move to centerscreen
    window.moveTo posLeft, posTop

end sub
'***********************************************************************
Sub BrowseSource_OnClick()
    strStartDir = "C:\work"
    Copy_To_PC.txtFile.value = PickFolder(strStartDir)
End Sub
'***********************************************************************
Function PickFolder(strStartDir)
    Dim SA, F
    Set SA = CreateObject("Shell.Application")
    Set F = SA.BrowseForFolder(0, "Choose a folder", 0, strStartDir)
    If (Not F Is Nothing) Then
        PickFolder = F.Items.Item.path
    End If
    Set F = Nothing
    Set SA = Nothing
End Function
'***********************************************************************
Sub Pickfile(InputFile)
    InputFile = Copy_To_PC.file1.value
    If InputFile ="" Then
        msgbox "Please you must select a file",vbExclamation,"choose file"
    Else
        msgBox "You have choosen this file " & InputFile,Vbinformation,"choose file"
    End If
End Sub
'***********************************************************************
Sub Copy
End Sub
'***********************************************************************
Sub Paste
    msgBox "Copy Success!"
End Sub
'***********************************************************************
Sub OpenWord
End Sub
'***********************************************************************
</script>
</head>
<body>
<p><b><font size="4">Please select the file.</font></b></p>
<form name="Copy_To_PC">
<input type="file" name="file1" id="file1"><br><br>
<input type = "button" value = "File Source" OnClick="pickfile(file1.value)"><br><br>
<input type = "text" name = "txtFile" size="100" />
<input type = "button" value = "Folder Source" Name="BrowseSource"><br><br>
<input type="button" value="Copy and Paste" name="RunScripts">
</form>
</body>
</html>

文件副本
行政长官
{
位置:绝对位置;
底部:10px;
右:10px
}
调用DoResize()
'***********************************************************************
亚多里斯
“调整大小
window.resizeTo 690350
screenWidth=Document.ParentWindow.Screen.AvailWidth
屏幕高度=Document.ParentWindow.Screen.AvailHeight
posLeft=(屏幕宽度-700)/2
posTop=(屏幕高度-430)/2
'移动到中心屏幕
window.movetoposleft,posTop
端接头
'***********************************************************************
子浏览器源_OnClick()
strStartDir=“C:\work”
将_复制到_PC.txtFile.value=PickFolder(strStartDir)
端接头
'***********************************************************************
函数PickFolder(strStartDir)
Dim SA,F
Set SA=CreateObject(“Shell.Application”)
设置F=SA.BrowseForFolder(0,“选择文件夹”,0,strStartDir)
如果(不是F什么都不是)那么
PickFolder=F.Items.Item.path
如果结束
设置F=无
设置SA=无
端函数
'***********************************************************************
子选取文件(输入文件)
InputFile=Copy_To_PC.file1.value
如果InputFile=”“,则
msgbox“请您选择一个文件”,VBE感叹号,“选择文件”
其他的
msgBox“您已选择此文件”&InputFile,Vbinformation,“选择文件”
如果结束
端接头
'***********************************************************************
子副本
端接头
'***********************************************************************
子粘贴
msgBox“复制成功!”
端接头
'***********************************************************************
次开放字
端接头
'***********************************************************************
请选择该文件








原始脚本中存在语法错误,可能会影响您。将NAVIGATABLE=“no”更改为NAVIGATABLE=“no”。很抱歉,如果此答案发布两次

我已编辑了您的标题。请看“”,其中的共识是“不,他们不应该”。谢谢与我分享。你能帮我在我的hta中为第一个按钮实现这个功能吗?我试过了,但有很多错误…谢谢,所以拿起的文件或文件夹必须分开吗?vbs不能在同一对话框窗口中执行这些操作?是的,文件或文件夹必须分开!:)