Table of Contents

Powershell

$CurrentPath = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent

With powershell V3

$PSScriptRoot

When converting ps1 to EXE (ps2exe), retrieving the script/exe path can be problematic. The variable that works is”

$PWD

vbs

Function GetPath()
   Dim path
  path = WScript.ScriptFullName
  GetPath = Left(path, InStrRev(path, "\"))
End Function

En batch

I often use %~dp0 in my scripts

echo %~d0
Returns the drive letter (C:).

echo %~n0
Returns file name without extension (script).

echo %~nx0
Returns file name and extension (script.bat).

echo %~x0
Returns the file extension (.bat).

echo %~f0
Returns the complete path in long format (C:\Documents and Settings\david\script.bat).

echo %~S0
Returns the complete path in long format (C:\Documents and Settings\david\script.bat).

echo %~sf0
Returns the complete path in short format  (C:\DOCUME~1\david\script.bat).

echo %~p0
Returns the path in long format without the file name or drive letter (\Documents and Settings\david\).

echo %~dp0
Returns the path in long format without the file name (C:\Documents and Settings\david\).

echo %~sp0
Returns the path in short format without the file name or drive letter (\DOCUME~1\david\).

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.