导航:首页 > 文件目录 > vb获取文件夹路径

vb获取文件夹路径

发布时间:2023-01-15 05:18:56

Ⅰ vb 完整路径获取文件夹路径

Path = "c:\soft\中国人\setup.exe"
For i = 1 To Len(Path)
If Mid(Path, i, 1) = "\" Then Print Left(Path, i)
Next i
或者:
Path = "c:\soft\中国人\setup.exe"
For i = 1 To Len(Path)
If Mid(Path, i, 1) = "\" Then Text1.Text = Left(Path, i)
Next i
将路径存回放于答text1内

Ⅱ VB 浏览文件夹获取文件夹路径

这个是我用VB做的文件选择器,仿Linux的资源浏览器!

Ⅲ vb获取启动文件夹路径

Private Const CSIDL_Users_STARTMENU_a = &H7 '当前用户\开始-程序-启动
' 声明API函数Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As LongPrivate Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As LongPrivate Function GetSpecialPath(CSIDL As Long) As String Dim s As Long Dim path As String Dim pidl As Long '根据指定的文件夹获得pidl s = SHGetSpecialFolderLocation(Me.hWnd, CSIDL, pidl) If s = NOERROR Then ' 根据r的返回值判断是否有错误发生,如果没有错误就获取文件夹路径 path = Space$(512) s = SHGetPathFromIDList(ByVal pidl, ByVal path) GetSpecialPath = Left$(path, InStr(path, Chr$(0)) - 1) Exit Function End If GetSpecialPath = ""End Function
Private Sub Form_Load()
msgbox GetSpecialPath(CSIDL_Users_STARTMENU_a) & "\"
End Sub 其它参数Private Const NOERROR = 0Private Const CSIDL_Users_FAVORITES = &H6 '当前用户\收藏夹Private Const CSIDL_Users_DESKTOPDIRECTORY = &H10 '当前用户\桌面Private Const CSIDL_Users_STARTMENU = &HB '当前用户\开始菜单Private Const CSIDL_Users_STARTMENU_cx = &H2 '当前用户\开始-程序Private Const CSIDL_Users_MyDocuments = &H5 '当前用户\我的文档Private Const CSIDL_Users_STARTMENU_a = &H7 '当前用户\开始-程序-启动Private Const CSIDL_Users_Recent = &H8 '当前用户\'RecentPrivate Const CSIDL_Users_SendTo = &H9 '当前用户\SendToPrivate Const CSIDL_Users_MyMusic = &HD '当前用户\My Documents\My Music\Private Const CSIDL_Users_NetHood = &H13 '当前用户\NetHoodPrivate Const CSIDL_Users_Templates = &H15 '当前用户\TemplatesPrivate Const CSIDL_Users_AppData = &H1A '当前用户\Application Data\Private Const CSIDL_Users_PrintHood = &H1B '当前用户\PrintHood\Private Const CSIDL_Users_Local_AppData = &H1C '当前用户\Local Settings\Application Data\Private Const CSIDL_Users_Temp = &H20 '当前用户\Local Settings\Temporary Internet Files\Private Const CSIDL_Users_Cookies = &H21 '当前用户\Cookies\Private Const CSIDL_Users_History = &H22 '当前用户\Local Settings\History\Private Const CSIDL_Users_Pictures = &H27 '当前用户\My Documents\My Pictures\Private Const CSIDL_Users = &H28 '当前用户\Private Const CSIDL_Users_gl = &H30 '当前用户\「开始」菜单\程序\管理工具\Private Const CSIDL_Users_CDBurning = &H3B '当前用户\Local Settings\Application Data\Microsoft\CD Burning\Private Const CSIDL_AllUsers_STARTMENU = &H16 'All Users\「开始」菜单\Private Const CSIDL_AllUsers_STARTMENU_cx = &H17 'All Users\「开始」菜单\程序\Private Const CSIDL_AllUsers_STARTMENU_j = &H18 'All Users\「开始」菜单\程序\启动\Private Const CSIDL_AllUsers_DESKTOPDIRECTORY = &H19 'All Users\桌面Private Const CSIDL_AllUsers_FAVORITES = &H1F 'All Users\Favorites\(收藏夹)Private Const CSIDL_AllUsers_Templates = &H2D 'All Users\Templates\Private Const CSIDL_AllUsers_Documents = &H2E 'All Users\Documents\Private Const CSIDL_AllUsers_gl = &H2F 'All Users\「开始」菜单\程序\管理工具\Private Const CSIDL_AllUsers_Music = &H35 'All Users\Documents\My Music\Private Const CSIDL_AllUsers_Pictures = &H36 'All Users\Documents\My Pictures\Private Const CSIDL_AllUsers_Videos = &H37 'All Users\Documents\My Videos\Private Const CSIDL_AllUsers_AppData = &H23 'All Users\Application Data\Private Const CSIDL_WinDows = &H24 '系统安装路径 C:\WINDOWS\Private Const CSIDL_WinSystem = &H25 '系统文件夹 C:\WINDOWS\system32\Private Const CSIDL_ProgramFiles = &H26 '应用程序安装文件夹 C:\Program Files\Private Const CSIDL__ProgramFiles_CommonFiles = &H2B 'C:\Program Files\Common Files\Private Const CSIDL_WIN_Resources = &H38 'C:\WINDOWS\Resources\Private Const CSIDL_font = &H14 '字体文件夹C:\WINDOWS\Fonts\

Ⅳ vb 得到文件路径

“当用Dialog一次打开多个文件”————你这里的Dialog指的是通用的OpenDialog“打开”对话框吗?

这样做:
引用Common Dialog 控件库。
在窗口上添加一个List1,一个Label1,两个按钮Command1和Command2,一个ComDlg控件命名为CD1。

然后加入以下代码

Option Explicit

Private Sub Command1_Click()
CD1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
CD1.ShowOpen
If CD1.FileName = "" Then Exit Sub
Dim Str1 As String
Dim Ary1() As String

Str1 = CD1.FileName
Ary1 = Split(Str1, Chr(0))

If UBound(Ary1) = 0 Then
ReDim Preserve Ary1(1)
Dim n1 As Long
n1 = InStrRev(Ary1(0), "\")
Ary1(1) = Mid(Ary1(0), n1 + 1)
Ary1(0) = Left(Ary1(0), n1)
End If

Dim s1 As Long, Apath1 As String
Apath1 = App.Path
If Right(Apath1, 1) <> "\" Then Apath1 = Apath1 & "\"
If Right(Ary1(0), 1) <> "\" Then Ary1(0) = Ary1(0) & "\"

Open Apath1 & "st.ini" For Output As #2
For s1 = 1 To UBound(Ary1)
Print #2, Ary1(0) & Ary1(s1)
Next
Close #2
End Sub

Private Sub Command2_Click()
Dim s1 As Long, Apath1 As String
Apath1 = App.Path
If Right(Apath1, 1) <> "\" Then Apath1 = Apath1 & "\"

Dim Str1 As String
Open Apath1 & "st.ini" For Input As #3
Do Until EOF(3)
Line Input #3, Str1
List1.AddItem Str1
Loop
Close #3
End Sub

Private Sub List1_Click()
If List1.ListIndex < 0 Then Exit Sub
Label1.Caption = List1.List(List1.ListIndex)
End Sub

ok,运行看看吧。
点击Command1会打开文件并把文件路径写入st.ini
点击Command2会读取st.ini,并显示到List1中
点击List1中的项目会在Label中显示内容。

完成了,已经在VB6下调试通过,给分吧~~

Ⅳ 如何用VB获得某一目录下的所有文件和文件夹名称

Dim a() As String
Private Sub Dir1_Change()
File1.Path = Dir1.Path
Label1.Caption = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo err1
Dir1.Path = Drive1.Drive
Exit Sub
err1:
MsgBox Err.Description, vbInformation + vbOKOnly, "提示"
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim ifieldcount As Integer, irecordcount As Integer
Dim wdapp As Word.Application
Dim wddoc As Word.Document
Dim atable As Word.Table
If Option2.Value = True Then
ReDim a(1 To File1.ListCount)
For i = 1 To File1.ListCount
b = File1.List(i)
a(i) = b
Next
End If
If Option1.Value = True Then
ReDim a(1 To Dir1.ListCount)
For i = 1 To Dir1.ListCount
b = Dir1.List(i)
a(i) = b
Next
End If
End Sub

这段程序 复制过去 就行了 创建的控件有 两个option 让你选择 要提取文件夹 还是文件路径的 选中option 1 就是提取文件夹的 option2 就是提取文件的 然后再创建 Drive1 Dir1 File1 这三个 选择文件路径的 控件 再加一个 command 按钮 就行了 有疑问再联系我!!!!!这个 只是 文件路径 你看看 是你想要的话 我再给你写 提取文件夹和文件名的代码!!!!

Ⅵ vb 如何通过一个文件的全路径获得该文件所在文件夹

'编写函数,获取
PrivateFunctionGetLuJIn(ByValaAsString)AsString
DimiAsLong
Fori=Len(a)To1Step-1
Ifmid(a,i,1)=""Then'获取最后一个""位置
GetLuJin=Left(a,i-1)'函数返回最后一个""前面的东西
ExitFunction'获取之后,函数没专什么事了,退出属
Endif
Nexti
EndFunction

Ⅶ vb 如何通过一个文件的全路径获得该文件所在文件夹

dim
s
as
string
dim
i
s="d:\123\123\asd\123.txt"
i=InStrRev(s,"\")
''最右侧
\
字符位置
s
=Left$(s,
i-1)
''s即是路径(文件夹)d:\123\123\asd
debug.print
s
''显示
d:\123\123\asd

Ⅷ VB获取文件夹路径

用API遍历当前桌面已打开的子窗口,获得窗口句柄和ID,然后通过ID获得该文件夹的路径,总之一句话,你要实现的功能VB无法做到,API可以

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

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

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

Ⅹ VB获取文件路径是怎么样的

VB2008测试通过 Imports System Imports System.IO Imports System.Threading Imports System.Windows.Formsx0dx0a Public Class FrmMainx0dx0ax0dx0aDim newSearcher As getFileByNamex0dx0ax0dx0a Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadx0dx0ax0dx0arball.Checked = Truex0dx0ax0dx0atbpath.Text = ""x0dx0ax0dx0atbpath.Enabled = Falsex0dx0ax0dx0abtndlg.Enabled = Falsex0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Clickx0dx0ax0dx0atv.Nodes.Clear()x0dx0ax0dx0abtnOK.Enabled = Falsex0dx0ax0dx0abtnExit.Enabled = Falsex0dx0ax0dx0aIf rball.Checked Thenx0dx0ax0dx0arun() tbpath.Text = "" Thenx0dx0ax0dx0aMsgBox("请输入或者选择一个路径")x0dx0ax0dx0aExit (tbpath.Text)x0dx0ax0dx0aEnd Ifx0dx0ax0dx0aEnd Ifx0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub btndlg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndlg.Clickx0dx0ax0dx0afbdlg.RootFolder = Environment.SpecialFolder.MyComputerx0dx0ax0dx0afbdlg.ShowDialog()x0dx0ax0dx0atbpath.Text = fbdlg.SelectedPathx0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub rbchs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbchs.CheckedChangedx0dx0ax0dx0aIf rbchs.Checked = True Thenx0dx0ax0dx0atbpath.Enabled = Truex0dx0ax0dx0abtndlg.Enabled = .Enabled = Falsex0dx0ax0dx0abtndlg.Enabled = Falsex0dx0ax0dx0aEnd Ifx0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub run()x0dx0ax0dx0aIf tbfileName.Text = "" Thenx0dx0ax0dx0aMsgBox("请输入文件名称")x0dx0ax0dx0abtnOK.Enabled = Truex0dx0ax0dx0abtnExit.Enabled = Truex0dx0ax0dx0aExit = New getFileByName(tbfileName.Text)x0dx0ax0dx0anewSearcher.GetDrivers()x0dx0ax0dx0atmr.Enabled = Truex0dx0ax0dx0atmr.Interval = 10x0dx0ax0dx0aEnd Ifx0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub run(ByVal path As String)x0dx0ax0dx0aIf tbfileName.Text = "" Thenx0dx0ax0dx0aMsgBox("请输入文件名称")x0dx0ax0dx0abtnOK.Enabled = Truex0dx0ax0dx0abtnExit.Enabled = Truex0dx0ax0dx0aExit = New getFileByName(tbfileName.Text)x0dx0ax0dx0anewSearcher.SearchFolder(path)x0dx0ax0dx0atmr.Enabled = Truex0dx0ax0dx0atmr.Interval = 50x0dx0ax0dx0aEnd Ifx0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tickx0dx0ax0dx0aLblshow.Text = newSearcher.currentPathx0dx0ax0dx0aIf newSearcher.cntThread = 0 And newSearcher.isDone Thenx0dx0ax0dx0a'MsgBox(newSearcher.getFile.ToString)x0dx0ax0dx0a'MsgBox("全部线程结束")x0dx0ax0dx0aFor Each Str As String In newSearcher.getFilex0dx0ax0dx0atv.Nodes.Add(Str)x0dx0ax0dx0aNextx0dx0ax0dx0a'For i As Integer = 0 To newSearcher.getFile.Length - 1x0dx0ax0dx0a'tv.Nodes.Add(newSearcher.getFile(i))x0dx0ax0dx0a'Nextx0dx0ax0dx0atmr.Enabled = Falsex0dx0ax0dx0abtnExit.Enabled = Truex0dx0ax0dx0abtnOK.Enabled = Truex0dx0ax0dx0aEnd Ifx0dx0ax0dx0aMy.Application.DoEvents()x0dx0ax0dx0aEnd Subx0dx0ax0dx0a Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Clickx0dx0ax0dx0aMe.Close()x0dx0ax0dx0aEnd Sub End Class

阅读全文

与vb获取文件夹路径相关的资料

热点内容
戴尔r910安装linux 浏览:69
有线电视升级失败 浏览:560
火绒安全把文件删掉了在哪里找 浏览:503
手机qq网络状态方框 浏览:225
哪里有文件纸袋 浏览:873
复制的东西能不能粘贴到空文件夹 浏览:876
酒店没有网络如何缴费 浏览:380
win10开机滚动很久 浏览:520
可对元数据实例进行的操作有什么 浏览:934
什么后缀的文件kit 浏览:295
word行书字体库下载 浏览:579
iosuc版本历史版本 浏览:14
电影字幕文件制作软件 浏览:723
windows10免密码登录 浏览:762
iphone5s跑步记步 浏览:978
手机网站设计怎么做好 浏览:322
中兴路由器修改密码 浏览:391
小米忘记压缩文件密码 浏览:716
cad哪些字体是形文件 浏览:2
word2007宝典pdf 浏览:46

友情链接