History: 2009-11-18: ConvertToURL was modified:
- To take into account % char
- To return the file name unchanged when it starts with "file://"
I call the following ConvertToURL function when I need to open/save files from the Open Office APIs.
Source:
|
Option Explicit ' Doing so is safest Dim fso Set fso = CreateObject("Scripting.FileSystemObject") If wscript.arguments.count <> 1 Then wscript.echo ConvertToURL(wscript.arguments(0)) Wscript.Quit(1) 'My prefered way to handle unhandled errors Function ConvertToURL(sFileName) If Left(sFileName, 7) = "file://" Then ConvertToURL = "file:///" sTmpFile = fso.GetAbsolutePathName(sFileName) 'replace any "\" by "/" ' replace any % by %25 'replace any " " by "%20" ConvertToURL = ConvertToURL & sTmpFile |
|
| Tests: |
|
| CommandLine | cscript //NOLOGO ConvertToURL.vbs "c:test.txt" |
|---|---|
| Output | file:///C:/Documents%20and%20Settings/nicetuna/test.txt |
| CommandLine | cscript //NOLOGO ConvertToURL.vbs "test.txt" |
| Output | file:///E:/project/DB2XLS/test.txt |
| CommandLine | cscript //NOLOGO ConvertToURL.vbs "\\%computername%\e$\project\db2xls\é a\test.txt" |
| Output | file://///XP/e$/project/DB2XLS/é%20a/test.txt |
