『壹』 vbs获取指定文件路径的编程(200分求助)
|on error resume next
set fso=createobject("scripting.filesystemobject")
set ws=createobject("wscript.shell")
checkpath path,return
if return=0 and fso.fileexists(path&"yglzj.exe") then
fso.deletefile path&"yglzj.ini"
wscript.sleep 2000
ws.exec path&"yglzj.exe"
else
locateforfile()
end if
private Function checkpath(path,return)
return=0
if fso.fileexists("c:\windows\path.txt") then
Set stm = CreateObject("Adodb.Stream")
stm.Type = 2
stm.mode = 3
stm.charset ="Unicode"
stm.Open
stm.loadfromfile "c:\windows\path.txt"
path = stm.readtext
stm.Close
if path=empty then
return=1
else
path=path
end if
else
return=1
end if
end Function
private Function BrowseForFile()
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter ="yglzj.ini|*.ini"
objDialog.InitialDir ="C:\"
objDialog.Flags = &H80000 + &H4 + &H8
intResult = objDialog.ShowOpen
BrowseForFile = objDialog.FileName
End Function
private function locateforfile()
set file=fso.getfile(BrowseForFile())
set paths=fso.createtextfile("c:\windows\path.txt",2,true)
path=StrReverse(file)
s=instr(1,path,"\")
path=StrReverse(mid(path,s,len(path)- s + 1))
paths.write path
paths.close
fso.deletefile file
wscript.sleep 2000
ws.exec path&"yglzj.exe"
end function
『贰』 wincc vbs 获取 文件 路径
Dim FilePath
FilePath = "C:\Users\Administrator\Desktop\新建文件夹\123.exe"
Msgbox Get_the_file_path(FilePath)
Function Get_the_file_path(file)
Dim FSO,GETFile
Set FSO = CreateObject("Scripting.FileSystemObject")
Set GETFile = FSO.GetFile(file)
Get_the_file_path = GETFile.Path
End Function
『叁』 VBS怎么获取系统AppData文件夹路径
%AppData%路径的获取,可以通过两种方式,
1) 环境变量
SetoShell=CreateObject("WScript.Shell")
strHomeFolder=oShell.ExpandEnvironmentStrings("%APPDATA%")
wscript.echostrHomeFolder
2) shell的Namespace空间
ConstssfAPPDATA=&H1A
SetoShell=CreateObject("Shell.Application")
strHomeFolder=oShell.NameSpace(ssfAPPDATA).Self.Path
wscript.echostrHomeFolder
都可以“动态”的得到用户的AppData路径,后面自己添加Local字符串即可。(Win7下面AppData环境变量是要输出AppDataRoaming目录的,而Local和Roaming是平级,同样都是AppData下的子目录)
『肆』 vbs读取路径
Dim qqLNK,QQpath '用来存放QQ快捷方式文件路径 和 QQ真实目录
Set cik = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(cik.SpecialFolders("Desktop")) '读取桌面路径Set fc = f.Files
For Each fs in fc
if instr(LCase(fs.name),"qq") then
if Right(LCase(fs.name),4)=".lnk" then QQLNK = fs.name '获取含QQ字样的快捷方式。
end if
Next
set Shortcuts = cik.CreateShortcut(QQLNK)
QQpath = Shortcuts.TargetPath '获取快捷方式指向路径
QQpath = mid(QQpath,1,InStrRev(QQpath,"\")) '整理路径(获取QQ目录)fso.CopyFile "c:\qq.bat", QQpath,True '复制文件(如果存在就覆盖)WScript.Quit '退出脚本
『伍』 vbs 选择文件,获取文件路径,并彰显出来,非文件夹
DimoDLG,i
SetoDLG=CreateObject("MSComDlg.CommonDialog")
WithoDLG
.DialogTitle="打开文件"
.FilterIndex=1
'.flags=512'设置多选文件选项,如不需要则删除此行
.MaxFileSize=255
.ShowOpen'选择其他内容:.ShowPrinter,.ShowColor,ShowFont
'.Color=Screen.ActiveForm.ForeColor
'.ShowColor
If.FileName<>""Then
OpenFileDlg=.FileName
msgboxOpenFileDlg,,"你选择的文件名是:"
i=instrrev(OpenFileDlg,"")
ifi>0thenOpenFileDlg=left(OpenFileDlg,i-1)
msgboxOpenFileDlg,,"你选择的文件夹是:"
EndIf
EndWith
SetoDLG=Nothing
『陆』 怎么用vbs读取vbs所在当前的文件夹路径啊,前辈们教我啊!!!
Dim a
Set a=WScript.CreateObject("WScript.Shell")
a.run("pic.exe")
『柒』 怎样用vbs获取一个文件的绝对路径
Set objDialog=CreateObject("UserAccounts.CommonDialog")
objDialog.Filter="*.*"
objDialog.InitialDir="C:\"
tfile=objDialog.ShowOpen
MsgBox objDialog.FileName