powered by simpleCommunicator - 2.0.61     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / whs - Окошко Открытие файла
10 сообщений из 10, страница 1 из 1
whs - Окошко Открытие файла
    #32997448
ASD_ROJD
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Нужна процедура или фун-я в результате работы которой откроется стандартное окошко открытия файла и после того как фаил будет выбран, можно будет получить полный путь местонахождения файла на винте.
Пример нужен для Windows Host Script на поддержке VBS.
Спасибо....
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #32997546
MoonRabbit
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Посмотрите вот этот код:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
<script language="VBScript">
    function fnShellBrowseForFolderVB()
        dim objShell
        dim ssfWINDOWS
        dim objFolder
        
        ssfWINDOWS =  36 
        set objShell = CreateObject("Shell.Application")
            set objFolder = objShell.BrowseForFolder( 0 , "Example",  0 , ssfWINDOWS)
                if (not objFolder is nothing) then
                    'Add code here.
                end if
            set objFolder = nothing
        set objShell = nothing
    end function
 </script>
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #32997568
MoonRabbit
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот здесь еще посмотрите:
http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_wqra.mspx
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #32997643
ASD_ROJD
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Спасибо за примеры поиска папок, но уточню нужно именно работать с файлом.
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #32998235
MoonRabbit
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Ндя... Промахнулся. Тогда может этот пример вам поможет (?):
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Sub DisplayOpenFileDialog()
    Dim openFile As New System.Windows.Forms.OpenFileDialog()
    openFile.DefaultExt = "doc"
    openFile.Filter = "Word documents (*.doc)|*.doc"
    openFile.ShowDialog()
    If openFile.FileNames.Length >  0  Then
        Dim filename As String
        For Each filename In openFile.FileNames
            ' Insert code here to process the files.
        Next
    End If
End Sub
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #32999906
ASD_ROJD
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
MoonRabbitНдя... Промахнулся. Тогда может этот пример вам поможет (?):
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
Sub DisplayOpenFileDialog()
    Dim openFile As New System.Windows.Forms.OpenFileDialog()
    openFile.DefaultExt = "doc"
    openFile.Filter = "Word documents (*.doc)|*.doc"
    openFile.ShowDialog()
    If openFile.FileNames.Length >  0  Then
        Dim filename As String
        For Each filename In openFile.FileNames
            ' Insert code here to process the files.
        Next
    End If
End Sub



что за класс system ?

в whs что то не видел....
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #33000605
MoonRabbit
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Вот, нашел такой пример:

Честно признаюсь, не проверял...

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
'********************************************************
' File:    FileSelectDialog.vbs (WSH sample in VBScript) 
' Author:  (c) G. Born
'
' Using the shell dialog box to select a folder
' or a file
' Warning: A run-time error occurs if the script
' is executed in Windows 2000 and the user selects
' a file in the root folder of a drive.
'********************************************************
Option Explicit

' Flags for the options parameter
Const BIF_returnonlyfsdirs   = &H0001
Const BIF_dontgobelowdomain  = &H0002
Const BIF_statustext         = &H0004
Const BIF_returnfsancestors  = &H0008
Const BIF_editbox            = &H0010
Const BIF_validate           = &H0020
Const BIF_browseforcomputer  = &H1000
Const BIF_browseforprinter   = &H2000
Const BIF_browseincludefiles = &H4000

Dim file

file = BrowseForFolder( _
        "Select a file or folder to copy", _
        BIF_returnonlyfsdirs + BIF_browseincludefiles, _
        "")
If file = "-5" Then 
    WScript.Echo "Not possible to select files in root folder"
Else
    If file = "-1" Then 
        WScript.Echo "No object selected; Cancel clicked"
    Else
        WScript.Echo "Object: ", file
    End If
End If 

' Using the shell's BrowseForFolder method to
' return the full path to the selected object
' title = Text shown in the dialog box
' flag = One of the values for controlling the 
'        BrowseForFolder behavior
' dir = Preselected directory (can be "")
Function BrowseForFolder(title, flag, dir)
    On Error Resume Next

    Dim oShell, oItem, tmp
 
    ' Create WshShell object.
    Set oShell = WScript.CreateObject("Shell.Application")

    ' Invoke Browse For Folder dialog box.
    Set oItem = oShell.BrowseForFolder(&H0, title, flag, dir)
    If Err.Number <>  0  Then
        If Err.Number =  5  Then
            BrowseForFolder= "-5"
            Err.Clear
            Set oShell = Nothing
            Set oItem = Nothing
            Exit Function
        End If
    End If

    ' Now we try to retrieve the full path.
    BrowseForFolder = oItem.ParentFolder.ParseName(oItem.Title).Path

    ' Handling: Cancel button and selecting a drive
    If Err<>  0  Then
        If Err.Number =  424  Then           ' Handle Cancel button.
            BrowseForFolder = "-1"
        Else
            Err.Clear
            ' Handle situation in which user selects a drive.
            ' Extract drive letter from the title--first search
            ' for a colon (:).
            tmp = InStr( 1 , oItem.Title, ":")
            If tmp >  0  Then           ' A : is found; use two 
                                      ' characters and add \.
                BrowseForFolder = _   
                    Mid(oItem.Title, (tmp -  1 ),  2 ) & "\"
            End If
        End If
    End If

    Set oShell = Nothing
    Set oItem = Nothing
    On Error GoTo  0 
End Function

'*** End
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #33002276
ASD_ROJD
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
MoonRabbitВот, нашел такой пример:

Честно признаюсь, не проверял...

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
'********************************************************
' File:    FileSelectDialog.vbs (WSH sample in VBScript) 
' Author:  (c) G. Born
'
' Using the shell dialog box to select a folder
' or a file
' Warning: A run-time error occurs if the script
' is executed in Windows 2000 and the user selects
' a file in the root folder of a drive.
'********************************************************
Option Explicit

' Flags for the options parameter
Const BIF_returnonlyfsdirs   = &H0001
Const BIF_dontgobelowdomain  = &H0002
Const BIF_statustext         = &H0004
Const BIF_returnfsancestors  = &H0008
Const BIF_editbox            = &H0010
Const BIF_validate           = &H0020
Const BIF_browseforcomputer  = &H1000
Const BIF_browseforprinter   = &H2000
Const BIF_browseincludefiles = &H4000

Dim file

file = BrowseForFolder( _
        "Select a file or folder to copy", _
        BIF_returnonlyfsdirs + BIF_browseincludefiles, _
        "")
If file = "-5" Then 
    WScript.Echo "Not possible to select files in root folder"
Else
    If file = "-1" Then 
        WScript.Echo "No object selected; Cancel clicked"
    Else
        WScript.Echo "Object: ", file
    End If
End If 

' Using the shell's BrowseForFolder method to
' return the full path to the selected object
' title = Text shown in the dialog box
' flag = One of the values for controlling the 
'        BrowseForFolder behavior
' dir = Preselected directory (can be "")
Function BrowseForFolder(title, flag, dir)
    On Error Resume Next

    Dim oShell, oItem, tmp
 
    ' Create WshShell object.
    Set oShell = WScript.CreateObject("Shell.Application")

    ' Invoke Browse For Folder dialog box.
    Set oItem = oShell.BrowseForFolder(&H0, title, flag, dir)
    If Err.Number <>  0  Then
        If Err.Number =  5  Then
            BrowseForFolder= "-5"
            Err.Clear
            Set oShell = Nothing
            Set oItem = Nothing
            Exit Function
        End If
    End If

    ' Now we try to retrieve the full path.
    BrowseForFolder = oItem.ParentFolder.ParseName(oItem.Title).Path

    ' Handling: Cancel button and selecting a drive
    If Err<>  0  Then
        If Err.Number =  424  Then           ' Handle Cancel button.
            BrowseForFolder = "-1"
        Else
            Err.Clear
            ' Handle situation in which user selects a drive.
            ' Extract drive letter from the title--first search
            ' for a colon (:).
            tmp = InStr( 1 , oItem.Title, ":")
            If tmp >  0  Then           ' A : is found; use two 
                                      ' characters and add \.
                BrowseForFolder = _   
                    Mid(oItem.Title, (tmp -  1 ),  2 ) & "\"
            End If
        End If
    End If

    Set oShell = Nothing
    Set oItem = Nothing
    On Error GoTo  0 
End Function

'*** End



у меня он был
Спасибо
Работает но опять же говорю только с папками.....
Мне надо что бы файлами было
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #33002394
Фотография PA
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
	Set objCommonDlg = CreateObject("MSComDlg.CommonDialog")
	With objCommonDlg
		.MaxFileSize =  260 
		.InitDir = "."
		.DialogTitle = "Выберите файл скрипта"
		.Filter = "Файлы WSH (*.vbs, *.js, *.wsf)|*.vbs; *.js; *.wsf"
		.FileName = ""
		.ShowOpen
		Wscript.Echo .FileName
	End With
Естественно, на машине д.б. установлен и зарегистрирован comdlg32.ocx...
...
Рейтинг: 0 / 0
whs - Окошко Открытие файла
    #33003134
ASD_ROJD
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
с оцх -ами не катит, надо так что бы просто заводилось на любой тачке
...
Рейтинг: 0 / 0
10 сообщений из 10, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / whs - Окошко Открытие файла
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]