Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open file in current dir 3

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
HI,

I have the following code inside my HTML file that opens a zip file in a given dir:

objShell.Run("""%ProgramFiles%\WinZip\winzip32.exe"" -e -o ""%userprofile%\Desktop\CREO-QZEDR9JVHI_20070130_sys.zip"" c:\TEMP")

I actually would like the code to open a zip file from my current dir - the one where the HTML files resides in.Something like:

objShell.Run("""%ProgramFiles%\WinZip\winzip32.exe"" -e -o "QZEDR9JVHI_20070130_sys.zip" c:\TEMP")

But it does not seem to find the zip file now ...
Appreciate any advice.
Thanks



Long live king Moshiach !
 
Have you tried putting .\ in front of the filename?

The question is, if you run the program from explorer, what is the current directory? It is easy to figure that out from the command prompt but in explorer it is not always the directory that the application was launced from.
 
Thanks.
putting .\ in front of the filename did not help.
The HTML and zip files are always in the same dir,but can be any dir on the FS.

Long live king Moshiach !
 
See if one of these works for you.

Code:
Dim objShell, WinZipPath, UsrDTPath
' 
Set objShell = CreateObject("WScript.Shell")

objShell.Run("""%ProgramFiles%\WinZip\winzip32.exe"" -e -o QZEDR9JVHI_20070130_sys.zip c:\TEMP")
' ==============================================================================================
WinZipPath = objShell.ExpandEnvironmentStrings("%ProgramFiles%") & "\WinZip\winzip32.exe"
objShell.Run(WinZipPath & " -e -o QZEDR9JVHI_20070130_sys.zip c:\TEMP")
' ==============================================================================================
objShell.Run("%comspec% /c ""%ProgramFiles%\WinZip\winzip32.exe"" -e -o QZEDR9JVHI_20070130_sys.zip c:\TEMP")
' ==============================================================================================
objShell.Run("%comspec% /c ""%ProgramFiles%\WinZip\winzip32.exe"" -e -o ""%userprofile%\Desktop\CREO-QZEDR9JVHI_20070130_sys.zip"" c:\TEMP")
' ==============================================================================================
UsrDTPath = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\Desktop\CREO-QZEDR9JVHI_20070130_sys.zip"
objShell.Run(WinZipPath & " -e -o " & UsrDTPath & " c:\TEMP")

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Thanks,

but I think my point is missed.
I move both HTML and ZIP files ANYWHERE on the disk,and need the VBscript part inside the HTML to be still be able to open the matching ZIP file.
Meaning the objShell.Run has to recognise the new current dir,not the %DESKTOP% or %PROGRAMFILES%,etc.
Thanks

Long live king Moshiach !
 
What if you change the extension to a .hta?

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
your solution is to write some code to determine where the .html file is located. in vbs i use the following to work out currentfolder


strCurrentFolder = UCase(Left(Wscript.ScriptFullName, Len(Wscript.ScriptFullName) - Len(Wscript.ScriptName) - 1))

'yes i am sure there are other ways
 
You can't use Wscript.ScriptFullName in a .html or .hta. I think you may have to change it to a .hta and workout those JavaScript/VBScript issues if you want to use

Set Sh=CreateObject("WScript.Shell")
cwd=Sh.CurrentDirectory
MsgBox "CurrentDirectory=" & cwd

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I know you said that mrmovie and just wanted to re-emphasize that in case anyone decided to try it.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
mrmovie,

so my actual line should looke like :

objShell.Run("""%ProgramFiles%\WinZip\winzip32.exe"" -e -o "strCurrentFolder & "QZEDR9JVHI_20070130_sys.zip"" c:\TEMP")


? or a different syntax for using a variable inside the objShell.Run expression ?
Thanks

Long live king Moshiach !
 
objShell.Run """%ProgramFiles%\WinZip\winzip32.exe"" -e -o " & strCurrentFolder & "\QZEDR9JVHI_20070130_sys.zip c:\TEMP"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
but you would still need to work out strCurrentFolder and perhaps wrap that in "" as well (or the whole string to your zip file) as dm4ever suggests my example code wont (probably) work in hta,...see below, i am sure there are better ways of doing it but it worked for what i was trying to do


strTemp = document.url
If Left(strTemp, 7) = "file://" Then
strTemp = Right(strTemp, Len(strTemp) - 7)
strCurrentFolder = Left(strTemp, InStrRev(strTemp, "\"))
End If

 
I tend to use a Function I wrote a while back for this. It returns the path correctly for both HTAs and HTMs that are loaded from a local filesystem source.
Code:
<html>
  <!-- saved from url=(0011)about:blank -->
  <head>
    <script language="VBScript">
      Option Explicit

      Function MyPath()
        'Get our source directory path from our current FILE URL
        'with trailing "\" included.
        Dim strPath, lngLastFolder

        'IE returns pathname with "/" delimiters, MSHTA with "\" instead.
        strPath = Replace(window.location.pathname, "/", "\")

        lngLastFolder = InStrRev(strPath, "\")

        'IE returns pathname with leading delimiter, MSHTA does not.
        If Left(strPath, 1) = "\" Then
          MyPath = Mid(strPath, 2, lngLastFolder - 1)
        Else
          MyPath = Left(strPath, lngLastFolder)
        End If
      End Function

      Sub cmdGetPath_onclick()
        txtPath.innerText = MyPath()
      End Sub
    </script>
  </head>
  <body>
    <p><input type="button" id="cmdGetPath" value="Get My Path"></p>
    <p id="txtPath"></p>
  </body>
</html>
 
Just like to further dilettante's advice.
[tt]
sub doit
dim s,t,wshshell
s=window.location
if strcomp(left(s,5),"file:",1)=0 then
set wshshell=createobject("wscript.shell")
t=replace(s,"file:///","")
t=replace(t,"/","\")
t=left(t,instrrev(t,"\")-1)
wshshell.currentdirectory=t
[green]'modulo anything else which need further adjustment on the commandline[/green]
wshshell.run """%ProgramFiles%\WinZip\winzip32.exe"" -e -o "QZEDR9JVHI_20070130_sys.zip" c:\TEMP")
set wshshell=nothing
else
msgbox "wshshell.run method does not support url protocol other than file."
end if
end sub
[/tt]
 
typo: The corresponding line should be read this (without the leftover right parenthesis). Furthermore, upon looking at op's original commandline, the quotes seem not right on the face of it. This is the minimum change.
[tt] wshshell.run """%ProgramFiles%\WinZip\winzip32.exe"" -e -o [highlight]Q[/highlight]ZEDR9JVHI_20070130_sys.zi[highlight]p[/highlight] c:\TEMP"[highlight] [/highlight]
[/tt]
 
Great thanks to all,guys and stars !
What worked eventually is :

strTemp = document.url
If Left(strTemp, 7) = "file://" Then
strTemp = Right(strTemp, Len(strTemp) - 7)
strCurrentFolder = Left(strTemp, InStrRev(strTemp, "\"))
End If

FullPath = strCurrentFolder & "HW00226_20070201_sys.zip"
objShell.Run("unzip -o " & FullPath & " -d c:\TEMP")

Long live king Moshiach !
 
Still one problem.
The baove code works great unless there are spaces in the FullPath (like Desktop causes "%20" to be part of it) -
Then the objShell.Run does not work.

I've tried the follwing code which does set the right FullPath ("d:\documents and settings\administrator\desktop\KDI-PGY2500_20070204_sys.zip" - no "%20" inside),but the unzip does not happen:

Set fso = CreateObject("Scripting.FileSystemObject")
strCurrentFolder = fso.GetAbsolutePathName(".")

FullPath = (strCurrentFolder & "\KDI-PGY2500_20070204_sys.zip")

objShell.Run("unzip -o " & FullPath & " -d c:\TEMP")

Will appreciate advise.

Long live king Moshiach !
 
Solved finally as following:

Set fso = CreateObject("Scripting.FileSystemObject")
strCurrentFolder = fso.GetAbsolutePathName(".")

FullPath = (strCurrentFolder & "\KDI-PGY2500_20070204_sys.zip")
FullPath1 = chr(34) & FullPath & chr(34)

objShell.Run("unzip -o " & FullPath1 & " -d c:\TEMP")


Long live king Moshiach !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top