フォルダを選択して、フォルダ内のファイル(含フォルダ)を列挙する |
|
Set Shell = CreateObject( "Shell.Application" )
' ダイアログ表示
Set objFolder = Shell.BrowseForFolder( 0, "フォルダ選択", 11, 0 )
' キャンセル
if objFolder is nothing then
WScript.Quit
end if
if not objFolder.Self.IsFileSystem then
WScript.Echo "ファイルシステムではありません"
WScript.Quit
end if
WScript.Echo objFolder.Self.Path
strItems = ""
' フォルダ内のコレクションを取得
Set objFolderItems = objFolder.Items()
' コレクションを列挙
nFiles = objFolderItems.Count
For I = 0 to nFiles - 1
Set objItem = objFolderItems.Item(I)
if objItem.isFolder then
strItems = strItems & objItem.Name & " [Folder]" & vbCrLf
else
strItems = strItems & objItem.Name & vbCrLf
end if
Next
' 全て表示
WScript.Echo strItems
VBScriptで、ビットをスイッチとして使う記述
BrowseForFolder Method
http://msdn.microsoft.com/en-us/library/bb774065(VS.85).aspx
プロパティ
http://msdn.microsoft.com/en-us/library/bb787808(VS.85).aspx
第3引数のフラグ
|
// For finding a folder to start document searching
#define BIF_RETURNONLYFSDIRS 0x0001
// For starting the Find Computer
#define BIF_DONTGOBELOWDOMAIN 0x0002
// Top of the dialog has 2 lines of text for BROWSEINFO.
//lpszTitle and one line if
#define BIF_STATUSTEXT 0x0004
// this flag is set. Passing the message BFFM_
// SETSTATUSTEXTA to the hwnd can set the
// rest of the text. This is not used with
// BIF_USENEWUI and BROWSEINFO.lpszTitle gets
// all three lines of text.
#define BIF_RETURNFSANCESTORS 0x0008
// Add an editbox to the dialog
#define BIF_EDITBOX 0x0010
// insist on valid result (or CANCEL)
#define BIF_VALIDATE 0x0020
// Use the new dialog layout with the ability to resize
#define BIF_NEWDIALOGSTYLE 0x0040
// Caller needs to call OleInitialize() before using this API
#define BIF_USENEWUI (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)
// Allow URLs to be displayed or entered.
// (Requires BIF_USENEWUI)
#define BIF_BROWSEINCLUDEURLS 0x0080
// Add a UA hint to the dialog, in place of the edit box.
// May not be combined with BIF_EDITBOX
#define BIF_UAHINT 0x0100
// Do not add the "New Folder" button to the dialog.
// Only applicable with BIF_NEWDIALOGSTYLE.
#define BIF_NONEWFOLDERBUTTON 0x0200
// don't traverse target as shortcut
#define BIF_NOTRANSLATETARGETS 0x0400
// Browsing for Computers.
#define BIF_BROWSEFORCOMPUTER 0x1000
// Browsing for Printers
#define BIF_BROWSEFORPRINTER 0x2000
// Browsing for Everything
#define BIF_BROWSEINCLUDEFILES 0x4000
// sharable resources displayed
// (remote shares, requires BIF_USENEWUI)
#define BIF_SHAREABLE 0x8000
| |
|
ファイルを表示する場合
|
Set Shell = CreateObject( "Shell.Application" )
on error resume next
Set objFolder = Shell.BrowseForFolder( 0, "フォルダ選択(ファイル表示)", 11 + &h4000, 0 )
if Err.Number <> 0 then
WScript.Echo "ファイルが選択されました"
WScript.Quit
end if
on error goto 0
if objFolder is nothing then
WScript.Quit
end if
if not objFolder.Self.IsFileSystem then
WScript.Echo "ファイルシステムではありません"
WScript.Quit
end if
WScript.Echo objFolder.Self.Path
| |
|
|
|
|
Set objFolder = Shell.BrowseForFolder( 0, "フォルダ選択", 11, 0 )
if objFolder is nothing then
WScript.Quit
end if
if not objFolder.Self.IsFileSystem then
WScript.Echo "ファイルシステムではありません"
WScript.Quit
end if
Set objThisFolder = Shell.NameSpace( WshShell.CurrentDirectory )
Call objThisFolder.CopyHere( objFolder.Self, 0 )
| |
|
|
選択したディレクトリ内のファイルをカレントにコピー |
|
|
Set objFolder = Shell.BrowseForFolder( 0, "フォルダ選択", 11, 0 )
if objFolder is nothing then
WScript.Quit
end if
if not objFolder.Self.IsFileSystem then
WScript.Echo "ファイルシステムではありません"
WScript.Quit
end if
Set objThisFolder = Shell.NameSpace( WshShell.CurrentDirectory )
Call objThisFolder.CopyHere( objFolder.Items(), 0 )
| |
|
|
|