Ⅰ vb 查找文件路径
你是要完成以下哪种工作?1、在本地磁盘中搜索QQ.EXE;2、查找当前正在运行的QQ.EXE的路径。对应1的回答:使用循环+Dir函数对应2的回答:使用以下API:openprocess,enumprocessmoles,getmolefilenameexa,closehandle,findwindow,getwindowthreadprocessid具体用法去查网络,到处都是
Ⅱ VB获取文件路径是怎么样的
VB2008测试通过 Imports System Imports System.IO Imports System.Threading Imports System.Windows.Forms Public Class FrmMainDim newSearcher As getFileByName Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadrball.Checked = Truetbpath.Text = ""tbpath.Enabled = Falsebtndlg.Enabled = FalseEnd Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Clicktv.Nodes.Clear()btnOK.Enabled = FalsebtnExit.Enabled = FalseIf rball.Checked Thenrun()ElseIf tbpath.Text = "" ThenMsgBox("请输入或者选择一个路径")Exit SubElserun(tbpath.Text)End IfEnd IfEnd Sub Private Sub btndlg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndlg.Clickfbdlg.RootFolder = Environment.SpecialFolder.MyComputerfbdlg.ShowDialog()tbpath.Text = fbdlg.SelectedPathEnd Sub Private Sub rbchs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbchs.CheckedChangedIf rbchs.Checked = True Thentbpath.Enabled = Truebtndlg.Enabled = TrueElsetbpath.Enabled = Falsebtndlg.Enabled = FalseEnd IfEnd Sub Private Sub run()If tbfileName.Text = "" ThenMsgBox("请输入文件名称")btnOK.Enabled = TruebtnExit.Enabled = TrueExit SubElsenewSearcher = New getFileByName(tbfileName.Text)newSearcher.GetDrivers()tmr.Enabled = Truetmr.Interval = 10End IfEnd Sub Private Sub run(ByVal path As String)If tbfileName.Text = "" ThenMsgBox("请输入文件名称")btnOK.Enabled = TruebtnExit.Enabled = TrueExit SubElsenewSearcher = New getFileByName(tbfileName.Text)newSearcher.SearchFolder(path)tmr.Enabled = Truetmr.Interval = 50End IfEnd Sub Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.TickLblshow.Text = newSearcher.currentPathIf newSearcher.cntThread = 0 And newSearcher.isDone Then'MsgBox(newSearcher.getFile.ToString)'MsgBox("全部线程结束")For Each Str As String In newSearcher.getFiletv.Nodes.Add(Str)Next'For i As Integer = 0 To newSearcher.getFile.Length – 1'tv.Nodes.Add(newSearcher.getFile(i))'Nexttmr.Enabled = FalsebtnExit.Enabled = TruebtnOK.Enabled = TrueEnd IfMy.Application.DoEvents()End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.ClickMe.Close()End Sub End Class
Ⅲ vb 得到文件路径
“当用Dialog一次打开多个文件”————你这里的Dialog指的是通用的OpenDialog“打开”对话框吗? 这样做: 引用Common Dialog 控件库。 在窗口上添加一个List1,一个Label1,两个按钮Command1和Command2,一个ComDlg控件命名为CD1。 然后加入以下代码: Option ExplicitPrivate Sub Command1_Click()CD1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorerCD1.ShowOpenIf CD1.FileName = "" Then Exit SubDim Str1 As StringDim Ary1() As StringStr1 = CD1.FileNameAry1 = Split(Str1, Chr(0))If UBound(Ary1) = 0 ThenReDim Preserve Ary1(1)Dim n1 As Longn1 = InStrRev(Ary1(0), "\")Ary1(1) = Mid(Ary1(0), n1 + 1)Ary1(0) = Left(Ary1(0), n1)End IfDim s1 As Long, Apath1 As StringApath1 = App.PathIf Right(Apath1, 1) <> "\" Then Apath1 = Apath1 & "\"If Right(Ary1(0), 1) <> "\" Then Ary1(0) = Ary1(0) & "\"Open Apath1 & "st.ini" For Output As #2For s1 = 1 To UBound(Ary1)Print #2, Ary1(0) & Ary1(s1)NextClose #2End SubPrivate Sub Command2_Click()Dim s1 As Long, Apath1 As StringApath1 = App.PathIf Right(Apath1, 1) <> "\" Then Apath1 = Apath1 & "\"Dim Str1 As StringOpen Apath1 & "st.ini" For Input As #3Do Until EOF(3)Line Input #3, Str1List1.AddItem Str1LoopClose #3End SubPrivate Sub List1_Click()If List1.ListIndex < 0 Then Exit SubLabel1.Caption = List1.List(List1.ListIndex)End Subok,运行看看吧。点击Command1会打开文件并把文件路径写入st.ini 点击Command2会读取st.ini,并显示到List1中 点击List1中的项目会在Label中显示内容。完成了,已经在VB6下调试通过,给分吧~~
Ⅳ vb 查找路径 并获得路径
首先用CommonDialog1.ShowOpen选中你需要的那个txt文件然后用CommonDialog1.FileName得到路径以及文件名就可以打开文件处理了下面的代码供参考DimtempAsStringDimallAsStringCommonDialog1.ShowOpenOpenCommonDialog1.FileNameForInputAs#1DoWhileNotEOF(1)Input#1,tempall=all&temp&Chr(13)&Chr(10)LoopClose#1Text1.Text=all
Ⅳ vb 选择文件 获取文件路径
首先在窗体中放置MicrosoftCommonDialogControl,名称指定为cdlg1。然后放一个按钮,内代码如容下:PrivateSubCommand1_Click()DimfnameAsStringDimcontentAsStringcdlg1.ShowOpenfname=cdlg1.FileNameMsgBoxfnameOpenfnameForInputAs#1Input#1,contentMsgBoxcontentClose#1EndSub
Ⅵ VB 中获取文件路径的函数
VB2008测试通过Imports SystemImports System.IOImports System.ThreadingImports System.Windows.FormsPublic Class FrmMain Dim newSearcher As getFileByName Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load rball.Checked = True tbpath.Text = "" tbpath.Enabled = False btndlg.Enabled = False End Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click tv.Nodes.Clear() btnOK.Enabled = False btnExit.Enabled = False If rball.Checked Then run() Else If tbpath.Text = "" Then MsgBox("请输入或者选择一个路径") Exit Sub Else run(tbpath.Text) End If End If End Sub Private Sub btndlg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndlg.Click fbdlg.RootFolder = Environment.SpecialFolder.MyComputer fbdlg.ShowDialog() tbpath.Text = fbdlg.SelectedPath End Sub Private Sub rbchs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbchs.CheckedChanged If rbchs.Checked = True Then tbpath.Enabled = True btndlg.Enabled = True Else tbpath.Enabled = False btndlg.Enabled = False End If End Sub Private Sub run() If tbfileName.Text = "" Then MsgBox("请输入文件名称") btnOK.Enabled = True btnExit.Enabled = True Exit Sub Else newSearcher = New getFileByName(tbfileName.Text) newSearcher.GetDrivers() tmr.Enabled = True tmr.Interval = 10 End If End Sub Private Sub run(ByVal path As String) If tbfileName.Text = "" Then MsgBox("请输入文件名称") btnOK.Enabled = True btnExit.Enabled = True Exit Sub Else newSearcher = New getFileByName(tbfileName.Text) newSearcher.SearchFolder(path) tmr.Enabled = True tmr.Interval = 50 End If End Sub Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.Tick Lblshow.Text = newSearcher.currentPath If newSearcher.cntThread = 0 And newSearcher.isDone Then 'MsgBox(newSearcher.getFile.ToString) 'MsgBox("全部线程结束") For Each Str As String In newSearcher.getFile tv.Nodes.Add(Str) Next 'For i As Integer = 0 To newSearcher.getFile.Length – 1 'tv.Nodes.Add(newSearcher.getFile(i)) 'Next tmr.Enabled = False btnExit.Enabled = True btnOK.Enabled = True End If My.Application.DoEvents() End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click Me.Close() End SubEnd Class
Ⅶ VB查找指定文件夹并获取文件路径的代码
1.首先打开来Excel电子表格,然自后在开发工具中打开VBA编辑器,如下图。
Ⅷ vb 获取文件所在路径
添加一个模块,模块里写:
SubMain()DimstrCmdAsStringstrCmd=Command()Form1.Label1.Caption=strCmdForm1.ShowEndSub
然后,在“工程”-“属性”-“通用”里设置启动对象为Sub Main()
Ⅸ VB获取文件路径
VB2008测试通过 Imports System Imports System.IO Imports System.Threading Imports System.Windows.Forms Public Class FrmMainDim newSearcher As getFileByName Private Sub FrmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadrball.Checked = Truetbpath.Text = ""tbpath.Enabled = Falsebtndlg.Enabled = FalseEnd Sub Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Clicktv.Nodes.Clear()btnOK.Enabled = FalsebtnExit.Enabled = FalseIf rball.Checked Thenrun()ElseIf tbpath.Text = "" ThenMsgBox("请输入或者选择一个路径")Exit SubElserun(tbpath.Text)End IfEnd IfEnd Sub Private Sub btndlg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndlg.Clickfbdlg.RootFolder = Environment.SpecialFolder.MyComputerfbdlg.ShowDialog()tbpath.Text = fbdlg.SelectedPathEnd Sub Private Sub rbchs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbchs.CheckedChangedIf rbchs.Checked = True Thentbpath.Enabled = Truebtndlg.Enabled = TrueElsetbpath.Enabled = Falsebtndlg.Enabled = FalseEnd IfEnd Sub Private Sub run()If tbfileName.Text = "" ThenMsgBox("请输入文件名称")btnOK.Enabled = TruebtnExit.Enabled = TrueExit SubElsenewSearcher = New getFileByName(tbfileName.Text)newSearcher.GetDrivers()tmr.Enabled = Truetmr.Interval = 10End IfEnd Sub Private Sub run(ByVal path As String)If tbfileName.Text = "" ThenMsgBox("请输入文件名称")btnOK.Enabled = TruebtnExit.Enabled = TrueExit SubElsenewSearcher = New getFileByName(tbfileName.Text)newSearcher.SearchFolder(path)tmr.Enabled = Truetmr.Interval = 50End IfEnd Sub Private Sub tmr_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr.TickLblshow.Text = newSearcher.currentPathIf newSearcher.cntThread = 0 And newSearcher.isDone Then'MsgBox(newSearcher.getFile.ToString)'MsgBox("全部线程结束")For Each Str As String In newSearcher.getFiletv.Nodes.Add(Str)Next'For i As Integer = 0 To newSearcher.getFile.Length – 1'tv.Nodes.Add(newSearcher.getFile(i))'Nexttmr.Enabled = FalsebtnExit.Enabled = TruebtnOK.Enabled = TrueEnd IfMy.Application.DoEvents()End Sub Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.ClickMe.Close()End Sub End Class
Ⅹ VB获取文件夹路径
用API遍历当前桌面已打开的子窗口,获得窗口句柄和ID,然后通过ID获得该文件夹的路径,总之一句话,你要实现的功能VB无法做到,API可以
未经允许不得转载:山九号 » vb获取文件的路径|vb 选择文件 获取文件路径