VBScript中已知一个全路径文件名,怎样解析出目录名及文件名(不包含目录)?

lizhyifeng2 2005-02-20 12:15:54
VBScript中已知一个全路径文件名,怎样解析出目录名及文件名(不包含目录)?
...全文
266 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
lizhyifeng2 2005-02-20
  • 打赏
  • 举报
回复
qzb0818(漂来漂去) ( 能否给个例子,我是新手。
qzb0818 2005-02-20
  • 打赏
  • 举报
回复
使用FilesystemObject
luckweb 2005-02-20
  • 打赏
  • 举报
回复
VB 中有属性和函数的区分(sub和function)

<SCRIPT LANGUAGE="VBScript">
Set fs=CreateObject("Scripting.FileSystemObject")
p=fs.GetParentFolderName("c:\a\a.txt")
msg=p
msgbox msg,vbyesno,"系统对话框"
</SCRIPT>
lizhyifeng2 2005-02-20
  • 打赏
  • 举报
回复
为什么我按楼上的写的代码:
<script language="VBScript">
sub parse

Set fs=CreateObject("Scripting.FileSystemObject")
p=fs.GetParentFolderName("c:\a\a.txt")
msg=p
aa=msgbox(msg,vbyesno,"系统对话框")

end sub


确没有效果。
yeaky 2005-02-20
  • 打赏
  • 举报
回复
asp函数FileSystemObject详解
Set fs=Server.CreateObject("Scripting.FileSystemObject")
1.文件是否存在
If (fs.FileExists("c:\winnt\cursors\3dgarro.cur"))=true Then
Response.Write("File c:\winnt\cursors\3dgarro.cur exists.")
Else
Response.Write("File c:\winnt\cursors\3dgarro.cur does not exist.")
End If
2.目录是否存在
If fs.FolderExists("c:\temp") = true Then
Response.Write("Folder c:\temp exists.")
Else
Response.Write("Folder c:\temp does not exist.")
End If
3.磁盘是否存在
if fs.driveexists("c:") = true then
Response.Write("Drive c: exists.")
Else
Response.Write("Drive c: does not exist.")
End If

Response.write("<br>")

if fs.driveexists("g:") = true then
Response.Write("Drive g: exists.")
Else
Response.Write("Drive g: does not exist.")
End If

4.获得文件所在的磁盘目录
p=fs.GetDriveName("c:\winnt\cursors\3dgarro.cur")
Response.Write("The drive name is: " & p)
结果:c:
5.获得文件所在的文件目录
p=fs.GetParentFolderName("c:\winnt\cursors\3dgarro.cur")
Response.Write("The parent folder name of c:\winnt\cursors\3dgarro.cur is: " & p)
结果:c:\winnt\cursors
6.获得文件的扩展名
Response.Write(fs.GetExtensionName("c:\winnt\cursors\3dgarro.cur"))
结果:cur
7.获得文件全名
Response.Write(fs.GetFileName("c:\winnt\cursors\3dgarro.cur"))
结果:3dgarro.cur
8.获得文件第一个名称
Response.Write(fs.GetBaseName("c:\winnt\cursors\3dgarro.cur"))
Response.Write("<br />")
Response.Write(fs.GetBaseName("c:\winnt\cursors\"))
Response.Write("<br />")
Response.Write(fs.GetBaseName("c:\winnt\"))
结果:3dgarro
cursors
winnt
set fs=nothing

62,266

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧