vb取文件路径|vb 选择文件 获取文件路径

vb取文件路径|vb 选择文件 获取文件路径的第1张示图

㈠ VB中如何获取当前程序的绝对路径

System.Environment.CurrentDirectory;

//例:c:/test/

Application.ExecutablePath;(包括名称)

//例:c:/test/myapp.exe

Application.StartupPath;(不包括名称)

//例:c:/test/

绝对路径是直接到达目标位置,通常是从盘符开始的路径。完整的描述文件位置的路径就是绝对路径,以web站点根目录为参考基础的目录路径。

绝对路径名的指定是从树型目录结构顶部的根目录开始到某个目录或文件的路径,由一系列连续的目录组成,中间用斜线分隔,直到要指定的目录或文件,路径中的最后一个名称即为要指向的目录或文件。之所以称为绝对,意指当所有网页引用同一个文件时,所使用的路径都是一样的。

(1)vb取文件路径扩展阅读

几种编程语言获取程序所在路径的方法:

1、在golang程序里面获取程序所在路径:

package main

import (

"path/filepath"

"os"

"fmt"

"log"

)

func main() {

execDir, err := filepath.Abs(filepath.Dir(os.Args[0]))

if err = nil {

log.Fatal(err)

}fmt.Println(execDir)

}

2、python脚本所在路径:

import os

print(os.path.split(os.path.realpath(__file__))[0])

3、shell脚本获取脚本的绝对路径:

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

㈡ 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 完整路径获取文件夹路径

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 查找文件路径

你是要完成以下哪种工作?1、在本地磁盘中搜索QQ.EXE;2、查找当前正在运行的QQ.EXE的路径。对应1的回答:使用循环+Dir函数对应2的回答:使用以下API:openprocess,enumprocessmoles,getmolefilenameexa,closehandle,findwindow,getwindowthreadprocessid具体用法去查网络,到处都是

㈥ 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 中获取文件路径的函数

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 选择文件 获取文件路径

首先在窗体中放置MicrosoftCommonDialogControl,名称指定为cdlg1。然后放一个按钮,内代码如容下:PrivateSubCommand1_Click()DimfnameAsStringDimcontentAsStringcdlg1.ShowOpenfname=cdlg1.FileNameMsgBoxfnameOpenfnameForInputAs#1Input#1,contentMsgBoxcontentClose#1EndSub

未经允许不得转载:山九号 » vb取文件路径|vb 选择文件 获取文件路径

赞 (0)