帮我看一下这个复制的问题吧

cbs1031 2004-07-05 05:47:39
Dim str1 As String
Dim str2 As String
Private Sub copy_Click() '复制函数
str1 = ExplorerList1.FileName '得到原文件的完整路径
End Sub
Private Sub del_Click()
Dim str4 As String
str1 = ExplorerList1.FileName
Kill str4
ExplorerList1.RefreshList True
ExplorerTree1.RefreshTree True
End Sub
Private Sub ExplorerList1_FolderClick()
ExplorerTree1.FolderClick (ExplorerList1.FileName)
End Sub
Private Sub ExplorerTree1_TreeDataChanged()
On Error Resume Next
ExplorerList1.TreeDatas = ExplorerTree1.TreeDatas
End Sub
Private Sub Form_Load()
ExplorerTree1.InitialDir = "c:\windows\system"
End Sub
Private Sub Form_Resize()
ExplorerTree1.Height = Me.ScaleHeight
ExplorerList1.Height = Me.ScaleHeight
End Sub
Private Sub icon_Click()
ExplorerList1.view = 0
End Sub
Private Sub list_Click()
ExplorerList1.view = 2
End Sub
Private Sub New_Click()
ExplorerList1.CreateDir
ExplorerList1.RefreshList True
End Sub

Private Sub paste_Click()    '粘贴函数
Dim str3 As Integer
str3 = ExplorerTree1.Path '拷贝到目标文件夹的路径
FileCopy str1, str3
End Sub
Private Sub report_Click()
ExplorerList1.view = 3
End Sub
Private Sub smallicon_Click()
ExplorerList1.view = 1
End Sub

我解决不了取得一个文件的文件名的问题,就像在c盘下的1.txt文件,我得到了
"c:\1.txt"的字符串,但是我还想要一个"1.txt"的字符串,应该怎么做呢?

...全文
164 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
libingao 2004-07-05
  • 打赏
  • 举报
回复
更正:
Str=Trim(Str)

For i = len(Str) to 1 setp -1
If Mid(Str,i,1) = "\" then Exit For
next i

If i<>1 Then FileNameStr=Right(Str,i+1) 应改为:
FileNameStr=Right(Str,Len(Str)-i) 或者:
FileNameStr=Mid(Str,i+1,Len(Str))
才对!不好意思!
cbs1031 2004-07-05
  • 打赏
  • 举报
回复
谢谢你们哈!
cbs1031 2004-07-05
  • 打赏
  • 举报
回复
不好意思,各位大侠,我想我是太笨了,什么都要问你们
libingao 2004-07-05
  • 打赏
  • 举报
回复
对于 "C;\2\1.txt" 的情况,可得出同样的结果:1.txt ,此时 i=5
libingao 2004-07-05
  • 打赏
  • 举报
回复
Str=Trim(Str)

For i = len(Str) to 1 setp -1
If Mid(Str,i,1) = "\" then Exit For
next i

If i<>1 Then FileNameStr=Right(Str,i+1)
cbs1031 2004-07-05
  • 打赏
  • 举报
回复
x = "c:\1.txt"
MsgBox Mid(x, InStrRev(x, "\") + 1)

我好像有点不懂,如果我是C;\2\1.txt
是不是也能得到同样的效果呢?
libingao 2004-07-05
  • 打赏
  • 举报
回复
你可先找到最右边的"\"位置,例如为:i
那么你可以用 Right(str,i+1) 来取得文件名!

注:原始路径和文件名称字符串 Str 应先去掉前导、后导空格才行!

csdnHelp 2004-07-05
  • 打赏
  • 举报
回复
楼上那个可能又问题(C:\test\test.txt)
csdnHelp 2004-07-05
  • 打赏
  • 举报
回复
你可以写一个函数
function GetShortName(StrPath as string ) as string
for i = len(trim(StrPath) ) to 1 setp -1
if right(i,1) = "\" then
endif
next i
end function
思路大楷如此!自己完成
好像有API函数也可以!!
northwolves 2004-07-05
  • 打赏
  • 举报
回复
x = "c:\1.txt"
MsgBox Mid(x, InStrRev(x, "\") + 1)

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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