VBScript Macro getParentFolder Name

前端 未结 2 348
清歌不尽
清歌不尽 2021-01-24 17:06

I am trying to create a vbscript macro which would get the folder location in which the macro is stored and create the output files into the same folder. I am using the below co

2条回答
  •  旧巷少年郎
    2021-01-24 17:48

    https://msdn.microsoft.com/en-us/library/22dyy47c%28v=vs.84%29.aspx

    That is not how the method works - it extracts the "parent" from the string provided.

       Option Explicit
       Dim fso,GetTheParent
    
       Set fso = CreateObject("Scripting.FileSystemObject")
       GetTheParent = fso.GetParentFolderName("C:\Windows")
       wscript.echo "Attempt 1:" & "'" & GetTheParent & "'"
    
       GetTheParent = fso.GetParentFolderName("\Windows")
       wscript.echo "Attempt 2:" & "'" & GetTheParent & "'"
    
       GetTheParent = fso.GetParentFolderName("Windows")
       wscript.echo "Attempt 3:" & "'" & GetTheParent & "'"
    
       GetTheParent = fso.GetParentFolderName("C:\WINDOWS\system32")
       wscript.echo "Attempt 4:" & "'" & GetTheParent & "'"
    
       GetTheParent = fso.GetParentFolderName("\WINDOWS\system32")
       wscript.echo "Attempt 5:" & "'" & GetTheParent & "'"
    

    Results:

    Attempt 1:'C:\'
    Attempt 2:''
    Attempt 3:''
    Attempt 4:'C:\WINDOWS'
    Attempt 5:'\WINDOWS'
    

提交回复
热议问题