『壹』 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