path=mid(wscriptscriptfullname,1,len(wscriptscriptfullname) - instr(1,strreverse(wscriptscriptfullname),"\") + 1)
msgbox path,,"你的存储路径是:"
这样可以获取文件存储的绝对路径,并且用msgbox显示出来
Option Explicit
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Const max_path = 260
Private Const max_path1 = 261
Private Sub Command1_Click()
Dim sysdir As String
Dim chrlen As Long
Dim windir As String
' 获得system路径
sysdir = Space(max_path)
chrlen = GetSystemDirectory(sysdir, max_path)
If chrlen > max_path Then chrlen = GetSystemDirectory(sysdir, chrlen)
sysdir = Left(sysdir, chrlen)
' 获得windows路径
windir = Space(max_path)
chrlen = GetWindowsDirectory(windir, max_path)
If chrlen > max_path Then chrlen = GetWindowsDirectory(windir, chrlen)
windir = Left(windir, chrlen)
' 在窗体上显示system路径
Label1Caption = "system的路径为: " & sysdir
' 在窗体上显示windows路径
Label2Caption = "windows的路径为: " & windir
End Sub
首先在窗体中放置 Microsoft Common Dialog Control,名称指定为 cdlg1。
然后放一个按钮,代码如下:
Private Sub Command1_Click()
Dim fname As String
Dim content As String
cdlg1ShowOpen
fname = cdlg1FileName
MsgBox fname
Open fname For Input As #1
Input #1, content
MsgBox content
Close #1
End Sub
Path = "c:\soft\中国人\setupexe"
For i = 1 To Len(Path)
If Mid(Path, i, 1) = "\" Then Print Left(Path, i)
Next i
或者:
Path = "c:\soft\中国人\setupexe"
For i = 1 To Len(Path)
If Mid(Path, i, 1) = "\" Then Text1Text = Left(Path, i)
Next i
将路径存放于text1内
@echo off
copy TABCTL32OCX %windir%\system32\TABCTL32OCX /y >nul
cd %windir%\system32
regsvr32 TABCTL32OCX /s
echo控件注册完成,任意键退出!
pause>nul
BAT写的,把这个bat和ocx放一起就可以了
在工具箱上右击,选择部件
在部件对话框中找到Microsoft Common Dialog Control 60 (sp3)
在窗口上创建CommonDialog1
双击按钮1在它的click事件中写入以下代码
CommonDialog1ShowOpen
If CommonDialog1FileName <> 0 Then
Text1Text = CommonDialog1FileName
End If
以上就是关于VB中如何直接获取文件的绝对路径全部的内容,包括:VB中如何直接获取文件的绝对路径、VB怎样获取系统盘路径、vb 选择文件 获取文件路径等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)