VBScript Datei- oder Ordnerauswahl
Ich habe eine kleine hta-Datei mit wenigen VBS-Codes. Es wählt einen Ordner oder eine Datei aus und erstellt dann eine Kopie an einem festen Speicherort.
<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 = "K:\Data\"
Copy_To_PC.txtFile.value = PickFolder(strStartDir)
End Sub
Function PickFolder(strStartDir)
Dim shell : Set shell = CreateObject("Shell.Application")
Dim file : Set file = shell.BrowseForFolder(0, "Choose a file:", &H4000)
If (Not File Is Nothing) Then
PickFolder = file.self.Path
End If
Set shell = Nothing
Set file = 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>
Ich habe Probleme beim Auswählen von Elementen (Ordner oder Datei), wenn ich auf die erste Schaltfläche klicke.
Es nimmt Ordner gut auf, aber wenn ich Dateien auswähle, bekomme ich "unspecified error on line 60", bitte hilf mir bei der Fehlersuche. Ich möchte, dass das Dateibrowser-Fenster so aussieht, wie es jetzt ist, und nicht, dass es sich um eine "Öffnen" -Schaltfläche handelt, sodass ich sowohl Ordner als auch Dateien auswählen kann.
Auch der Dateibrowser startet nicht von dem Ort aus, den ich eingerichtet habe. Wie man es repariert