FolderItem.Name 属性
设置或获取项的名称。
此属性是可读写的。
语法
strName = FolderItem.Name
FolderItem.Name = strName
属性值
BSTR 类型的变量,用于指定或接收项的名称。
示例
以下示例使用 Name 检索Autoexec.bat文件的名称,然后将名称重置为 Test.bat。 显示 JScript、VBScript 和 Visual Basic 的正确用法。
Jscript:
<script language="JScript">
function fnNameGetSetJ()
{
var objShell = new ActiveXObject("shell.application");
var objFolder2;
objFolder2 = objShell.NameSpace("C:\\");
if (objFolder2 != null)
{
var objFolderItem;
objFolderItem = objFolder2.ParseName("AUTOEXEC.BAT");
if (objFolderItem != null)
{
var szReturn;
szReturn = objFolderItem.Name;
objFolderItem.Name = "TEST.BAT";
}
}
}
</script>
VBScript:
<script language="VBScript">
function fnNameGetSetVB()
dim objShell
set objShell = CreateObject("shell.application")
if (not objShell is nothing) then
dim objFolder2
set objFolder2 = objShell.NameSpace("C:\")
if (not objFolder2 is nothing) then
dim objFolderItem
set objFolderItem = objFolder2.ParseName("AUTOEXEC.BAT")
if (not objFolderItem is nothing) then
dim szReturn
szReturn = objFolderItem.Name
objFolderItem.Name = "TEST.BAT"
end if
set objFolderItem = nothing
end if
set objFolder2 = nothing
end if
set objShell = nothing
end function
</script>
Visual Basic:
Private Sub fnNameGetSetVB()
Dim objShell As Shell
Dim objFolder2 As Folder2
Set objShell = New Shell
Set objFolder2 = objShell.NameSpace("C:\")
If (Not objFolder2 Is Nothing) Then
Dim objFolderItem As FolderItem
Set objFolderItem = objFolder2.ParseName("AUTOEXEC.BAT")
If (Not objFolderItem Is Nothing) Then
Dim szReturn As String
szReturn = objFolderItem.Name
objFolderItem.Name = "TEST.BAT"
Else
'FolderItem object returned nothing.
End If
Set objFolderItem = Nothing
Else
'Folder object returned nothing.
End If
Set objFolder2 = Nothing
Set objShell = Nothing
End Sub
要求
要求 | 值 |
---|---|
最低受支持的客户端 |
Windows 2000 专业版、Windows XP [仅限桌面应用] |
最低受支持的服务器 |
Windows 2000 Server [仅限桌面应用] |
标头 |
|
IDL |
|
DLL |
|