vb 获得选中文件夹或文件路径

我在窗体中做了一个Dri1和一个File1,以及一个Text1 Command1(复制),command2(删除),command3(剪切),command4(粘贴)现在,我想实现以下功能:
1.当选中Dri1的文件目录或是File1的文件时,Text1能马上显示这个路径
(注意是选中,不是其他事件,就是单击一下选中那种)
2.复制这个选中的文件夹或文件,(无条件复制,就是文件夹中如果有文件或是无文件照样复制)到桌面,再好不用其他控件或是API,引用等.
3.条件同上,删除,剪切,粘贴等操作能进行,并能够马上刷新显示.
我想做一个像是资源管理器工具条那种菜单的功能.请高手指教.
要有代码,测试过了再发过来!

以下是我的代码,已经测试通过:

Dim fso As Object
Dim wsh As Object
Dim DesktopPath As String
Dim bReady As Boolean

Public Function formatPath(sPath As String) As String
formatPath = sPath
If Right(sPath, 1) <> "\" Then formatPath = sPath & "\"
End Function

Private Sub Form_Load()
Set fso = CreateObject("Scripting.FileSystemObject")
Set wsh = CreateObject("WScript.Shell")
DesktopPath = wsh.SpecialFolders("Desktop") & "\" '获取桌面路径

bReady = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set fso = Nothing
Set wsh = Nothing
End Sub

Private Sub Dir1_Change()
File1.Path = Dir1.Path ' 当目录改变时,设置文件路径.
End Sub

Private Sub File1_Click()
sPath = formatPath(Dir1.List(Dir1.ListIndex)) '获取选择的路径

Text1.Text = sPath & File1.FileName

bReady = True
End Sub

Private Sub Command1_Click() '复制
If bReady = True Then fso.CopyFile Text1.Text, DesktopPath & File1.FileName
End Sub

Private Sub Command2_Click() '删除
If bReady = True Then fso.DeleteFile Text1.Text: File1.Refresh
End Sub

Private Sub Command3_Click() '剪切
If bReady = True Then fso.MoveFile Text1.Text, DesktopPath & File1.FileName: File1.Refresh
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-02-15
1.
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Text1 = Dir1.Path
End Sub

Private Sub Dir1_Click()
Dir1.Path = Dir1.List(Dir1.ListIndex)
End Sub

Private Sub File1_Click()
Text1 = Replace(Dir1.Path & "\", "\\", "\") & File1.FileName
End Sub
相似回答
大家正在搜