【问题标题】:How to get the fully qualified path for a file in VBScript?如何在 VBScript 中获取文件的完全限定路径?
【发布时间】:2010-03-23 17:11:35
【问题描述】:

我正在使用Shell.Application 对象,它允许我编写 zip 文件的脚本创建。

但为了让它工作,我需要 zip 文件的完整路径。 File.zip 不起作用。我需要c:\the\full\path\file.zip,即使脚本在找到文件的同一目录中运行。

如何获取VBScript中文件的完整路径?

类似于 cmd.exe shell 中的 %~fI 扩展。

【问题讨论】:

    标签: vbscript path


    【解决方案1】:

    Scripting.FileSystemObject 上,有一个名为GetAbsolutePathName 的方法可以做到这一点。

    这对我有用:

    Dim folderName
    folderName = "..\.."
    
    Dim fso
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Dim fullpath
    fullpath = fso.GetAbsolutePathName(folderName)
    
    WScript.Echo "folder spec: " & folderName
    WScript.Echo "fullpath:    " & fullpath
    

    【讨论】:

      【解决方案2】:

      例如

      Set objFS=CreateObject("Scripting.FileSystemObject")
      Set objArgs = WScript.Arguments
      strFile= objArgs(0)
      Set objFile = objFS.OpenTextFile(strFile)
      Set objFile = objFS.GetFile(strFile)
      WScript.Echo objFile.Path 
      

      在命令行上

      c:\test> cscript //nologo myscript.vbs myfile
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-04-28
        • 2010-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多