Long Path Problem using WScript.Arguments

374 Views Asked by At

In continuation of Call VBScript from Windows Explorer Context Menu, I managed to get a VBScript file running from SendTo in the Windows Explorer.

I've changed my code to copy the file that invokes the script to my Temp folder. The new problem is that if the path is over 256 characters, I can't loop through WScript.Arguments to get all of it. Is there another way to get the full path (including the file name and it's extension)?

Option Explicit

Call OpenDocuWorksFile

Sub OpenDocuWorksFile()
    Const sTitle = "Open DocuWorks File"
    
    Dim iArgumentsCount
    Dim iArgument
    Dim sFilePath
    Dim sTempFolder
    Dim oFileScriptingObject
    Dim sFileName
    Dim oShell
    
    iArgumentsCount = WScript.Arguments.Count
    
    On Error Resume Next
    
    For iArgument = 0 To iArgumentsCount
        
        sFilePath = sFilePath & WScript.Arguments(iArgument)
        
    Next
    
    On Error GoTo 0
    
    Set oFileScriptingObject = CreateObject("Scripting.FileSystemObject")
    
    With oFileScriptingObject
        
        sFileName = .GetFileName(sFilePath)
        
        sTempFolder = oFileScriptingObject.GetSpecialFolder(2) 'Temp Folder
        
        If .GetExtensionName(sFileName) = "xdw" Then
            
            .CopyFile sFilePath, sTempFolder & "\", True 'Overwrite
            
            Set oShell = CreateObject("Shell.Application")
            
            oShell.Open sTempFolder & "\" & sFileName
            
        Else
            
            MsgBox "Please select a DocuWorks file.(.xdw)", vbCritical, sTitle
            
        End If
        
    End With
    
    Set oFileScriptingObject = Nothing
    
    Set oShell = Nothing
    
End Sub
0

There are 0 best solutions below