Can a WSH script tell which directory it is running in? 
Author Message
 Can a WSH script tell which directory it is running in?

Hi,
    Can a WSH  script tell which directory it is running in? Like App.path
in VB.

Thanks in advance



Tue, 28 Jan 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?
Thanks , it works.


Quote:
> Hi,

> msgbox left(wscript.scriptfullname,

instrrev(wscript.scriptfullname,"\")-1)
Quote:

>   Thorsten




Quote:
> > Hi,
> >     Can a WSH  script tell which directory it is running in? Like
App.path
> > in VB.

> > Thanks in advance



Tue, 28 Jan 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?
A bit of trivia...

Just so you know, that isn't always the same a the "current directory" at the file system level.  I
know "current directory" isn't what you asked about - the reply you got from Thorsten is 100%
correct given that you wanted the equivalent of VB's App.Path property.  But a lot of people assume
that the two are the same.

The script below will *always* give you the true current directory at the file system level, at
least at the point in the code that it's called.

set fso = createobject("scripting.filesystemobject")
currdir = fso.getabsolutepathname(".")
msgbox currdir

It all depends on how you execute the script:

* If executed by double clicking the script file in Windows Exporer (or using the context menu Open
command), then they are the same.

* If executed explicitly with wscript.exe from a console window (aka DOS box) then it will be
whatever directory is current in that console window.

* If executed explicitly with wscript.exe from Start Menu's Run dialog then it will be the Desktop
folder.

* If executed via a shortcut (.lnk) it will be whatever was specified as the "Start in" directory
for the shortcut or the Windows (%windir%) directory if no "Start in: was specified.

Remember, I said this was trivia, but I got burned (once) by assuming the script's "app.path" was
actually the current directory.  The worst part of getting burned was that the script was a "page
generator" that created several hundred static HTML pages using a pair of XML files as a data
source.  As it turned out, the desktop was that current directory and the files were written without
full paths, so...

My lesson learned - don't assume the current directory and *always* use fully qualified paths...

--
Michael Harris
Microsoft MVP - Scripting

"It always helps to read the documentation..."

Quote:

> Thanks , it works.



> > Hi,

> > msgbox left(wscript.scriptfullname,
> instrrev(wscript.scriptfullname,"\")-1)

> >   Thorsten



> > > Hi,
> > >     Can a WSH  script tell which directory it is running in? Like
> App.path
> > > in VB.

> > > Thanks in advance



Tue, 28 Jan 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?
Minor correction:

* If executed via a shortcut (.lnk) it will be whatever was specified as the "Start in" directory
for the shortcut or the directory containing the .lnk file itself if no "Start in: was specified.
If the .lnk is executed from the Run dialog, it's the Desktop folder again...

--
Michael Harris
Microsoft MVP - Scripting

"It always helps to read the documentation..."


Quote:
> A bit of trivia...

> Just so you know, that isn't always the same a the "current directory" at the file system level.
I
> know "current directory" isn't what you asked about - the reply you got from Thorsten is 100%
> correct given that you wanted the equivalent of VB's App.Path property.  But a lot of people
assume
> that the two are the same.

> The script below will *always* give you the true current directory at the file system level, at
> least at the point in the code that it's called.

> set fso = createobject("scripting.filesystemobject")
> currdir = fso.getabsolutepathname(".")
> msgbox currdir

> It all depends on how you execute the script:

> * If executed by double clicking the script file in Windows Exporer (or using the context menu
Open
> command), then they are the same.

> * If executed explicitly with wscript.exe from a console window (aka DOS box) then it will be
> whatever directory is current in that console window.

> * If executed explicitly with wscript.exe from Start Menu's Run dialog then it will be the Desktop
> folder.

> * If executed via a shortcut (.lnk) it will be whatever was specified as the "Start in" directory
> for the shortcut or the Windows (%windir%) directory if no "Start in: was specified.

> Remember, I said this was trivia, but I got burned (once) by assuming the script's "app.path" was
> actually the current directory.  The worst part of getting burned was that the script was a "page
> generator" that created several hundred static HTML pages using a pair of XML files as a data
> source.  As it turned out, the desktop was that current directory and the files were written
without
> full paths, so...

> My lesson learned - don't assume the current directory and *always* use fully qualified paths...

> --
> Michael Harris
> Microsoft MVP - Scripting

> "It always helps to read the documentation..."


> > Thanks , it works.



> > > Hi,

> > > msgbox left(wscript.scriptfullname,
> > instrrev(wscript.scriptfullname,"\")-1)

> > >   Thorsten



> > > > Hi,
> > > >     Can a WSH  script tell which directory it is running in? Like
> > App.path
> > > > in VB.

> > > > Thanks in advance



Tue, 28 Jan 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?
Hi,

msgbox left(wscript.scriptfullname, instrrev(wscript.scriptfullname,"\")-1)

  Thorsten


Quote:
> Hi,
>     Can a WSH  script tell which directory it is running in? Like App.path
> in VB.

> Thanks in advance



Wed, 29 Jan 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?

Hi, I followed your instructions and the result was correct when double
clicking the vbs file where as when schedueling the job in my vb schedueler
or winat it gives me the directory where the application resides.
I did the following :
    set fso = createobject("scripting.filesystemobject")
    currdir = fso.getabsolutepathname(".")
    X = "ex" & Y & M & D & ".log" zipFileName = "ex" & Y & M & D
    msgbox "pkzip " & currdir & "\" & zipFileName & " " & currdir & "\" & X
Any help would be appreciated. is there a work around for this issu?

Salam


Quote:
> A bit of trivia...

> Just so you know, that isn't always the same a the "current directory" at

the file system level.  I
Quote:
> know "current directory" isn't what you asked about - the reply you got

from Thorsten is 100%
Quote:
> correct given that you wanted the equivalent of VB's App.Path property.

But a lot of people assume
Quote:
> that the two are the same.

> The script below will *always* give you the true current directory at the

file system level, at
Quote:
> least at the point in the code that it's called.

> set fso = createobject("scripting.filesystemobject")
> currdir = fso.getabsolutepathname(".")
> msgbox currdir

> It all depends on how you execute the script:

> * If executed by double clicking the script file in Windows Exporer (or

using the context menu Open
Quote:
> command), then they are the same.

> * If executed explicitly with wscript.exe from a console window (aka DOS

box) then it will be
Quote:
> whatever directory is current in that console window.

> * If executed explicitly with wscript.exe from Start Menu's Run dialog

then it will be the Desktop
Quote:
> folder.

> * If executed via a shortcut (.lnk) it will be whatever was specified as

the "Start in" directory
Quote:
> for the shortcut or the Windows (%windir%) directory if no "Start in: was
specified.

> Remember, I said this was trivia, but I got burned (once) by assuming the

script's "app.path" was
Quote:
> actually the current directory.  The worst part of getting burned was that

the script was a "page
Quote:
> generator" that created several hundred static HTML pages using a pair of
XML files as a data
> source.  As it turned out, the desktop was that current directory and the

files were written without
Quote:
> full paths, so...

> My lesson learned - don't assume the current directory and *always* use

fully qualified paths...
Quote:

> --
> Michael Harris
> Microsoft MVP - Scripting

> "It always helps to read the documentation..."




Quote:
> > Thanks , it works.



> > > Hi,

> > > msgbox left(wscript.scriptfullname,
> > instrrev(wscript.scriptfullname,"\")-1)

> > >   Thorsten



> > > > Hi,
> > > >     Can a WSH  script tell which directory it is running in? Like
> > App.path
> > > > in VB.

> > > > Thanks in advance



Mon, 03 Feb 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?

Hi, Thorsten and all,

    WScript.ScriptFullName & "\.."

is simpler and works at least on 2k/NT. The system only does a textual
analysis of paths and "peels off" the previous component if it encounters a
"..".

Uwe
----------------


Quote:
> Hi,

> msgbox left(wscript.scriptfullname,

instrrev(wscript.scriptfullname,"\")-1)
Quote:

>   Thorsten




Quote:
> > Hi,
> >     Can a WSH  script tell which directory it is running in? Like
App.path
> > in VB.

> > Thanks in advance



Mon, 03 Feb 2003 03:00:00 GMT  
 Can a WSH script tell which directory it is running in?


Fri, 19 Jun 1992 00:00:00 GMT  
 Can a WSH script tell which directory it is running in?

I try to call a excel procedure with a parameter. How can I do this ?
Is there any way to do this ?

'--------------------------------------------------
'
'--------------------------------------------------
Sub fit_to_page(file)

Dim objXL

 Set objXL = WScript.CreateObject("Excel.Application")
   objXL.Visible = TRUE
' objXL.Visible = FALSE
  objXL.Workbooks.Open "\\fred07\bin\xla\excel_fit_to_page.xls"
 objXL.Workbooks.Open file
  objXl.Application.Windows(1).Activate
 objXl.Application.Run "excel_fit_to_page.xls!fit2page_quer"

 ' ?? try ??
 objXl.Application.Run "excel_fit_to_page.xls!fit2page_quer" & "(" &file & ")"
 ' ?? try  ??
 objXl.Application.Run "excel_fit_to_page.xls!fit2page_quer" & " " &file & " "

  objXl.Application.Windows(1).Close
 objXl.Quit

End Sub



Sun, 16 Feb 2003 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Non-script process telling a wsh script to quit (nicely)

2. How to tell if script is running from Schedule service

3. How can I tell what directory my script is running from?

4. Detecting the current directory from with an WSH script

5. how can tell if another specific task is running

6. How can I tell if a program is already running

7. Is there a way to tell which applications are running

8. Not running, am I doing something wrong

9. How can I tell if a program is already running

10. Am I running in safe Mode?

11. Determining Which OS I am running and what SP level

12. need vb script to change users home directory in on fell swoop (active directory)

 

 
Powered by phpBB® Forum Software